I am loading a url into my page on my local server with PHP file_get_contents. It works fine but relative paths on the site I am pulling obviously fail and default to my localhost.
Does anyone have any advice on how I could swap relative paths of a page I am pulling to absolute ones?
Ive tried something like this but it fails...
$homepage = file_get_contents($theURL);
$homepage2 = str_replace($homepage, "/images", $theURL + '/images');
echo $homepage2;
Thanks!
You're arguments for str_replace
are in the wrong order.
Instead of
$homepage2 = str_replace($homepage, "/images", $theURL + '/images');
You should be doing
$homepage2 = str_replace("/images", $theURL + '/images', $homepage);
str_replace(search, replace, subject)