我想创建一个包含include函数的页面。此页面应该抓取另一个站点,并可以使用此函数str_replace更改文本或代码。我希望有可能。我已经编写了这段代码,但遗憾的是它不起作用:
<?php
$text = include('http://www.example.com/index.html');
$text = str_replace("<div id=\"hercss\">Hello.</div>", "<div id=\"mycss\">Welcome!</div>", $text);
echo $text;
?>
也许你有解决方案?你会完全赞赏它。
答案 0 :(得分:2)
试试这个:
<?php
$url = "http://www.example.com/index.html";
$text = file_get_contents($url);
$text = str_replace("<div id=\"hercss\">Hello.</div>", "<div id=\"mycss\">Welcome!</div>", $text);
echo $text;
?>
我认为只包含相关链接吗?函数file_get_contents
跨域工作