为什么我看不到页面上呈现的PHP代码?
Just getting started with php. In index.php I have
<?php
echo 'test';
?>
and when I go to localhost:8080/php/index.php I see 'test'. However I made an HTML file index.html with this code:
<html>
<body>
<?php include 'index.php'; ?>
<h1>Welcome to my home page!</h1>
</body>
</html>
but all I see is 'Welcome to my home page' and no 'test'. Wondering what I'm missing here.
Thanks!
Change the file extension from .html
to .php
Change index.html
to index.php
NOTE: You can't execute php code in .html
files.
Also one more thing, you need to change both file names. because you are changing index.html to index.php and another file with same name is already there.
so do this.
index_inc.php
<?php
echo 'test';
?>
index.php
<html>
<body>
<?php include 'index_inc.php'; ?>
<h1>Welcome to my home page!</h1>
</body>
</html>
Your file's extension is .html
, so php code will not be excuted.
if you really want to let the .html file to excute php code, you can write a .htaccess
file
and add the line
AddType application/x-httpd-php .php .html