phphtmlwebmatrix

Why does some PHP code render as HTML comments


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.


Solution

  • 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