PHP 代码停止正常加载网站

发布于 2024-11-26 09:07:54 字数 1875 浏览 1 评论 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);

?>

此代码位于文件中,我使用

由于某种原因,我包含该文件后的任何其他文件都将不起作用,例如

任何帮助将不胜感激 对不起我的英语

丹尼尔,


我得到了这个:注意:未定义的变量:do_not_duplicate in /usr/local/pem/vhosts/135377/webspace/httpdocs/folder/wp-content/themes/one/index.php on line 47警告:in_array ():第二个参数的数据类型错误/usr/local/pem/vhosts/135377/webspace/httpdocs/folder/wp-content/themes/one/index.php on line 47

错误消息与之前提供的代码无关,错误消息有一些内容对于 WordPress,第 47 行是这样的代码: ID, $do_not_duplicate)) 继续; ?>


  • 更新 1

    错误消息显示:

    解析错误:语法错误,/usr/local/pem/vhosts/135377 中意外的 $end /webspace/.../newfile.php(26) :第 1 行 eval() 的代码

    解析错误:语法错误,意外的 $end in /usr/local/pem/vhosts/135377/webspace/.../newfile.php(30) :第 1 行的 eval() 代码

    致命错误:无法在 /usr/local/pem/ 中中断/继续 1 级vhosts/135377/webspace/.../newfile.php on line 32


    更新2

    没有错误消息,但页脚的内容() 位于网站的源代码中,但用户不可见。 (如果我检查网站的源代码,我可以找到页脚文件的所有元素,但这些元素未在浏览器上正确呈现)

    I have this code to get the HTML source of a website/file and replace some parts of its content. Later I print the modified result

    <?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);
    
    ?>
    

    This code is in a file, I include this code using <?php include('newfile.php'); ?>

    For some reason any other file after I include that file will not work, like <?php include('somefile.php'); ?> or <?php get_footer(); ?>

    Any help will be appreciated
    Sorry for my English

    Daniel


    I got this: Notice: Undefined variable: do_not_duplicate in /usr/local/pem/vhosts/135377/webspace/httpdocs/folder/wp-content/themes/one/index.php on line 47 Warning: in_array(): Wrong datatype for second argument in /usr/local/pem/vhosts/135377/webspace/httpdocs/folder/wp-content/themes/one/index.php on line 47

    The error message has nothing to do with the code provided before, the error message has someting to do with Wordpress, on line 47 is this code: <?php while (have_posts()) : the_post(); if (in_array($post->ID, $do_not_duplicate)) continue; ?><li class="contentli">


    Update 1

    Error message says:

    Parse error: syntax error, unexpected $end in /usr/local/pem/vhosts/135377/webspace/.../newfile.php(26) : eval()'d code on line 1

    Parse error: syntax error, unexpected $end in /usr/local/pem/vhosts/135377/webspace/.../newfile.php(30) : eval()'d code on line 1

    Fatal error: Cannot break/continue 1 level in /usr/local/pem/vhosts/135377/webspace/.../newfile.php on line 32


    Update 2

    There is no error message but the content of the footer (<?php get_footer(); ?>) is on the source code of the site but not visible to users. (If I check the source code of the site i can find all the elements of the footer file, but these elements aren't properly rendered on the browser)

    如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

    扫码二维码加入Web技术交流群

    发布评论

    需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

    评论(3

    夜唯美灬不弃 2024-12-03 09:07:54

    你在循环中没有做任何事情......也许代码应该是:

    <?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);
    
    } 
    ?>
    

    Your not doing anything in you're loop... perhaps code should be:

    <?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);
    
    } 
    ?>
    
    自此以后,行同陌路 2024-12-03 09:07:54

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

    You are using a file function.please declare a link variable. for reference, please check this http://php.net/manual/en/function.file.php

    半暖夏伤 2024-12-03 09:07:54

    您很可能遇到了错误,但您并不知道。因此,让我们尝试获取更多信息。对于文件顶部,请考虑以下内容:

    <?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.
    

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

    如果您遇到任何错误,请将其添加到您的问题中。

    It's highly likely that you've got an error but you don't know about it. So let's try to get some more info. Consider the following for the top of the file:

    <?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.
    

    continue with the rest of the file as-is. This will enable reporting all errors and displaying them. Hope this helps.

    If you get any errors, please add them to your question.

    ~没有更多了~
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文