Click here to Skip to main content
15,041,788 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
test.html
===========
XML
<html>
<head>
    <title>Get web visitor's location</title>
    <meta name="robots" value="none" />
</head>
<body>
<div id="yourinfo">
<? php echo 'hello'; ?>
</div>
</body>
</html>

==================
file output in web browser:
XML
<html><head>
    <title>Get web visitor's location</title>
    <meta name="robots" value="none">
</head>
<body>
<div id="yourinfo">
<!--? php echo 'hello'; ?-->
</div>

</body></html>

================================
please help me why php script is comment out in html file?

Godaddy Windows hosting is in use..!!!
Posted

1 solution

First, because your file has extension "html" (test.html) the web server will not process as PHP. PHP files need to have extension .php if not php2 or php3 if you're using those.

Second, I believe you have a space in between the opening tag with question mark and the word "php". Those should be altogether as in

PHP
<?php    ... code ... ?> 
   
v2
Comments
Sanjeev236 6-Oct-13 18:44pm
   
I want to use php in html page so extension is .html and neither extension and nor space after question mark can lead a browser to comment out php script.
And I tried after removing the space yet result is same. anyways, thanks a lot.
Homero Rivera 6-Oct-13 22:37pm
   
But did you try to change the file extension? Perhaps, if run on Apache Server, it will comment the php code if it does not meet a file with php extension.

The extension of the file is irrelevant to all web browsers; php files are still html files to the eyes of the client. The extension of the file tells the server that it should run php commands and will not deprive the result from its status as HTML. Therefore, if you don't use the php extension, the server will never know it should run the php code you have in it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900