如何将file_get_contents与相对路径一起使用


How to use file_get_contents with relative paths

当我在使用相对路径的页面上使用此脚本时,我无法拥有页面样式和图像。

$homepage = file_get_contents('http://thewebsite.com');
echo $homepage;

有什么技巧可以让它发挥作用吗?

使用PHP将base元标记插入html:的头部

<base href="http://thewebsite.com/">

PHP代码看起来像这样:

$homepage = file_get_contents('http://thewebsite.com');
$homepageArray = explode("<head>", $homepage);
$newHomepage = implode("<head><base href='"http://thewebsite.com/'">",$homepageArray);
echo $newHomepage;