简体   繁体   中英

PHP code is being printed as HTML comments

I am having the following piece of code in a php file:

    <?php
    include_once('includes/connection.php');
    include_once('includes/article.php');

    $article =  new Article;
    $articles = $article->fetch_all();
    ?>
<html>....</html>

Instead of getting the expected result, I get the message "fetch_all(); ?>, which means that the above code is treated as HTML comment. I have read the similar threads(that blame the short_open_tag value mainly) around but didn't help me at all. Any ideas?

Edit: Many thanks for your responses. Seems that the specific weird problem was about an update on my Linux system which messed up a little my permissions. I changed the user to http instead of root and the problem is gone.

The problem is somewhere inside either includes/connection.php or includes/article.php . A line in there seems to indicate the start of the comment which goes all the way down to the -> part.

In case you did not installed php. you might look at WAMP server. It includes php en mysql and works great on your local (windows) computer.

http://www.wampserver.com/en/

Is this your output?

Your code isn't being parsed by PHP and there might be several reasons for it:

  • Check your URL. Does it look like you're fetching the file directly ( C:\\Users\\Name\\... ) or are you going through your host http://localhost/file.php .

  • Check your file extensions. Make sure it's .php and not .html .

  • Check your server capabilities. Is PHP installed?

This specific problem was brought about by an update on my Linux system, which messed up my permissions a little. I changed the user in the Apache directory to http instead of root, and the problem is now gone.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM