Replace relative url's with absolute
Join the DZone community and get the full member experience.Join For Free
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; }
Opinions expressed by DZone contributors are their own.