I have a dynamic php code as follows
$url = "http://www.myweb.com/home";
$mycontents = 'These are the contents with <a href="myweb/local.php" />relative link</a> and <a href="http://www.myweb.com/home/loc.php"> absolute link</a> and some images with <img src="myweb/local.jpg" /> with relative link and <img src="http://www.myurl.com/pictures/pic.jpg" />';
$url
and $mycontents
are changing depending on the data fetched, even links contained changes. Any function that will SCAN for the variable $mycontents
and if found any link with a or src, check first to see if is absolute, if yes, leave it, if no, using str_replace str_replace("src=\"", "src=\"".$url, $mycontents)
and change all links before echoing $mycontents, Target is, once $mycontents get echoed, has to be modified with all relative links scanned and found changed to absolute.