Why does some PHP code render as HTML comments

六眼飞鱼酱① 提交于 2019-12-12 16:09:08

问题


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.

For example this line:

<?
include "phpinfo.php";    
?>

becomes:

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

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


回答1:


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.

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

try the following line in your php file:

<?php phpinfo() ?>

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

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



来源:https://stackoverflow.com/questions/30158095/why-does-some-php-code-render-as-html-comments

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!