简体   繁体   English

PHP代码被打印为HTML注释

[英]PHP code is being printed as HTML comments

I am having the following piece of code in a php file: 我在php文件中有以下代码:

    <?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? 我没有得到预期的结果,而是收到消息“ fetch_all();?>,这意味着上面的代码被视为HTML注释。我已经阅读了类似的线程(主要归咎于short_open_tag值),但没有帮我一点忙,有什么想法吗?

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. 似乎特定的怪异问题是有关我的Linux系统上的更新,这弄乱了我的权限。 I changed the user to http instead of root and the problem is gone. 我将用户更改为http而不是root,问题消失了。

The problem is somewhere inside either includes/connection.php or includes/article.php . 问题出在includes/connection.phpincludes/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. 如果您没有安装php。 you might look at WAMP server. 您可能会看一下WAMP服务器。 It includes php en mysql and works great on your local (windows) computer. 它包括php和mysql,在本地(Windows)计算机上运行良好。

http://www.wampserver.com/en/ 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: 您的代码没有被PHP解析,可能有几个原因:

  • Check your URL. 检查您的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 . 它看起来像是您直接获取文件( C:\\Users\\Name\\... )还是正在浏览主机http://localhost/file.php

  • Check your file extensions. 检查您的文件扩展名。 Make sure it's .php and not .html . 确保它是.php而不是.html

  • Check your server capabilities. 检查您的服务器功能。 Is PHP installed? 是否已安装PHP?

This specific problem was brought about by an update on my Linux system, which messed up my permissions a little. 这个特定问题是由我的Linux系统上的更新引起的,该更新使我的权限有些混乱。 I changed the user in the Apache directory to http instead of root, and the problem is now gone. 我将Apache目录中的用户更改为http而不是root,现在问题消失了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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