包含str_replace函数?

时间:2013-10-10 14:17:13

标签: php include echo str-replace

我想创建一个包含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;
?>

也许你有解决方案?你会完全赞赏它。

1 个答案:

答案 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跨域工作