我有这个代码来获得一个网站/文件的HTML源,并取代其内容的某些部分。然后打印修改后的结果
<?php
// Get a file into an array. In this example we'll go through HTTP to get
// the HTML source of a URL.
$lines = file($link);
// Loop through our array, show HTML source as HTML source; and line numbers too.
foreach ($lines as $line_num => $line) {
}
?>
<?php
$old = array("document.write(", "'", ")", "<a href="", "</a>", "target="_blank"");
$new = array("", "", "", "", "", "");
$original = htmlspecialchars($line);
$changed = str_replace($old, $new, $original);
?>
此代码在一个文件中,我使用<?php include('newfile.php'); ?>
由于某种原因,我包含该文件后的任何其他文件将不工作,如<?php include('somefile.php'); ?>
或<?php get_footer(); ?>
任何帮助将不胜感激对不起我的英语
丹尼尔我得到了这个:注意:未定义的变量:do_not_duplicate在/usr/local/pem/vhosts/135777/webspace/httpdocs/folder/wp-content/themes/one/index.php在第47行警告:in_array():错误的数据类型第二个参数在/usr/local/pem/vhosts/135777/webspace/httpdocs/folder/wp-content/themes/one/index.php
错误信息与之前提供的代码无关,错误信息与Wordpress有关,第47行是这样的代码:<?php while (have_posts()) : the_post(); if (in_array($post->ID, $do_not_duplicate)) continue; ?><li class="contentli">
更新1
错误提示:
解析错误:语法错误,$end in/usr/local/pem/vhosts/135377/webspace/……/newfile.php(26): eval()'d code on line 1
解析错误:语法错误,$end in/usr/local/pem/vhosts/135377/webspace/……/newfile.php(30): eval()'d code on line 1
致命错误:无法在/usr/local/pme/vhosts/135377/webspace/……/newfile.php的第32行上打破/继续1级
更新2
没有错误信息,但是页脚(<?php get_footer(); ?>
)的内容在站点的源代码上,但对用户不可见。(如果我检查网站的源代码,我可以找到页脚文件的所有元素,但这些元素没有正确呈现在浏览器上)
你在你的循环中没有做任何事情…也许代码应该是:
<?php
// Get a file into an array. In this example we'll go through HTTP to get
// the HTML source of a URL.
$lines = file($link);
// Loop through our array, show HTML source as HTML source; and line numbers too.
foreach ($lines as $line_num => $line) {
$old = array("document.write(", "'", ")", "<a href="", "</a>", "target="_blank"");
$new = array("", "", "", "", "", "");
$original = htmlspecialchars($line);
$changed = str_replace($old, $new, $original);
}
?>
您正在使用一个文件函数。请声明一个链接变量。参考请查看此http://php.net/manual/en/function.file.php
很有可能你已经得到了一个错误,但你不知道它。让我们试着得到更多的信息。考虑以下文件的顶部:
<?php
error_reporting(~0);
ini_set('display_errors', 1);
// Get a file into an array. In this example we'll go through HTTP to get
// the HTML source of a URL.
继续按原样处理文件的其余部分。这将启用报告所有错误并显示它们。希望对你有帮助。
如果你有任何错误,请把它们添加到你的问题