为什么某些 PHP 代码呈现为 HTML 注释 [英] Why does some PHP code render as HTML comments

查看:38
本文介绍了为什么某些 PHP 代码呈现为 HTML 注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始学习 PHP 并安装了 webmatrix 以开始使用.我的第一个测试页面将一些 PHP 代码呈现为 HTML 注释.我需要帮助确定出了什么问题.一个 include 语句工作正常,而另一个在同一个文件中的输出如下所示.没有任何带有 HTML 的 PHP 代码显示.该文件包含 HTML 和 PHP 代码,并以 .PHP 扩展名命名.我确实在站点设置中启用了 PHP.

I just started learning PHP and installed webmatrix to get started. My first test page renders some of the PHP code as HTML comments. I need help determining what's wrong. One include statement works fine while another in the same file outputs as seen below. None of the PHP code withing HTML displays. The file contains HTML and PHP code and is named with a .PHP extension. I do have PHP enabled in the site settings.

例如这一行:

<?
include "phpinfo.php";    
?>

变成:

<!--? include "phpinfo.php"; ?-->

05/11:感谢大家的帮助.我开始使用它并学到了一些东西.

05/11: Thanks for all the help. I got it working and learned a few things.

推荐答案

理想情况下,您应该使用 打开和 ?> 关闭 php 语句待评估.如果您只想打印一个值,您可以使用短标签 ?>.

You should ideally be using <?php to open and ?> to close php statements to be evaluated. You can use short-tags <?= and ?> if you just want to print a value.

在我看来,无论哪种方式,您的 Web 服务器都没有呈现 php.当标签 <? 被浏览器接收到时,浏览器会将其视为不应该呈现给最终用户的东西(实际上它不应该 - 它应该由您的发送到客户端之前).

Either way it looks to me like php isn't being rendered by your web server. When the tag <? is received by the browser, the browser treats it as something which shouldn't be rendered to the end user (which indeed it shouldn't - it should be getting evaluated by your server prior to being sent to the client).

在您的 php 文件中尝试以下行:

try the following line in your php file:

如果这不起作用,那么您需要检查 php 是否真的在您的服务器上运行.

If this doesn't work then you need to check if php is actually running on your server.

如果它确实有效,那么正如 Darren 在下面评论的那样,您的 php.ini 文件中可能没有设置为允许的短标签 - 请参阅 SO 答案 这里

If it does work then as Darren commented below it is likely that you do not have short-tags set to allowed in your php.ini file - see SO answer here

这篇关于为什么某些 PHP 代码呈现为 HTML 注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆