Over a million developers have joined DZone.

Replace relative url's with absolute

·

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:

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

{{ parent.tldr }}

{{ parent.urlSource.name }}