file_get_contents内部的相对路径结果



我使用php file_get_contents将URL加载到本地服务器上。它可以正常工作,但是在网站上的相对路径我显然会失败,默认为我的本地主机。

有人对我如何交换一个我要把的页面相对路径有任何建议吗?

ive尝试了这样的事情,但失败了...

$homepage = file_get_contents($theURL);
$homepage2 = str_replace($homepage, "/images", $theURL + '/images');
echo $homepage2;

谢谢!

您的str_replace的参数为错误的顺序。

而不是

$homepage2 = str_replace($homepage, "/images", $theURL + '/images');

你应该做

$homepage2 = str_replace("/images", $theURL + '/images', $homepage);

http://php.net/str_replace

str_replace(search, replace, subject)

最新更新