我有这个代码来获取网站/文件的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(); ?>
任何帮助将不胜感激 对不起我的英文
丹尼尔
我得到了这个:注意:未定义的变量:第47行的/usr/local/pem/vhosts/135377/webspace/httpdocs/folder/wp-content/themes/one/index.php中的do_not_duplicate警告:in_array() :第47行/usr/local/pem/vhosts/135377/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
错误消息说:
解析错误:语法错误,/usr/local/pem/vhosts/135377/webspace /.../newfile.php(26)中的意外$ end:第1行的eval()代码
解析错误:语法错误,/usr/local/pem/vhosts/135377/webspace /.../newfile.php(30)中的意外$ end:第1行的eval()代码
致命错误:无法在第32行的/usr/local/pem/vhosts/135377/webspace/.../newfile.php中断/继续1级
更新2
没有错误消息,但页脚的内容(<?php get_footer(); ?>
)位于网站的源代码上,但对用户不可见。 (如果我检查网站的源代码,我可以找到页脚文件的所有元素,但这些元素在浏览器上没有正确呈现)
答案 0 :(得分:0)
你在循环中没有做任何事情......也许代码应该是:
<?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);
}
?>
答案 1 :(得分:0)
您正在使用文件function.please声明一个链接变量。供参考,请查看http://php.net/manual/en/function.file.php
答案 2 :(得分:0)
你很可能有错误,但你不知道。所以让我们尝试获取更多信息。请考虑以下文件顶部:
<?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.
按原样继续保留文件的其余部分。这将启用报告所有错误并显示它们。希望这会有所帮助。
如果您收到任何错误,请将其添加到您的问题中。