Running PHP displays the code itself

At times we get posting on the forum where user complain that when they are running a PHP file, the output is the file itself. This means that the script was not recognized as a PHP script and rather it was treated as plain text by the browser. There are two reasons why you can run into this situation to my knowledge.

If you are using short tags for writing PHP script like <? echo 'Hello World' ?>, you should ensure that you have short_open_tag INI directive set to '1' in your PHP INI file. If this is not the case the script will not be treated as PHP script. I would prefer PHP script like <?php echo 'Hello World' ?>. This is more clear and avoids confusion.

Another reason for running into this situation can be if the PHP file is not saved as ASCII/ANSI. Saving the PHP script in UNICODE/Multi-byte format will again fail the script to be recognized as PHP script. Always save the PHP script as plain text file to avoid running into this situation.

Hopefully this will help some of you in getting around this problem. Thanks for patient reading and good bye.

Don

3 Comments

  • thanks solved my problem with this !!!

  • I have the same problem. I created a virtual dir c:\inetpub\wwwroot\vdir that is for the site c:\inetpub\wwwroot\site
    When the folder was under \site php worked ok. When I move the folder to wwroot - php send the file to the output.
    Any ideas (the 2 above didn't help)
    Thanks.

  • Please report this to PHP forum at http://forums.iis.net/1102.aspx.

    Thanks,
    Don.

Comments have been disabled for this content.