开发者

PHP code stop normal loading of site

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(", "'", ")", "&lt;a href=&quot;", "&lt;/a&gt;", "target=&quot;_blank&quot;"); 
 $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)


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(", "'", ")", "&lt;a href=&quot;", "&lt;/a&gt;", "target=&quot;_blank&quot;"); 
    $new = array("", "", "", "", "", "");
    $original = htmlspecialchars($line);
    $changed = str_replace($old, $new, $original);

} 
?>


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜