0

我有这段代码来获取网站/文件的 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(", "'", ")", "&lt;a href=&quot;", "&lt;/a&gt;", "target=&quot;_blank&quot;"); 
 $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(); ?>) 的内容在网站的源代码上,但用户看不到。(如果我检查网站的源代码,我可以找到页脚文件的所有元素,但这些元素没有在浏览器上正确呈现)

4

3 回答 3

0

您正在使用文件函数。请声明一个链接变量。供参考,请查看此http://php.net/manual/en/function.file.php

于 2011-07-25T15:55:01.523 回答
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.

继续按原样处理文件的其余部分。这将启用报告所有错误并显示它们。希望这可以帮助。

如果您有任何错误,请将它们添加到您的问题中。

于 2011-07-25T15:55:08.137 回答
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(", "'", ")", "&lt;a href=&quot;", "&lt;/a&gt;", "target=&quot;_blank&quot;"); 
    $new = array("", "", "", "", "", "");
    $original = htmlspecialchars($line);
    $changed = str_replace($old, $new, $original);

} 
?>
于 2011-07-25T15:53:29.700 回答