Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Replace relative url's with absolute

DZone's Guide to

Replace relative url's with absolute

·
Free Resource

This snippet will replace all anchor that have relative url's to be absolute to whatever domain you provide. I use it often so I thought I would share.



 ]*href\s*?=[\"'])(?!http)([^\"'>]+)([\"'>]+)#";
$html=preg_replace($pattern,$replace, $html);
return $html;

}
Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}