duancai1904
2013-11-02 07:35 浏览 27
已采纳

为什么我看不到页面上呈现的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!

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答 默认 最新

  • 已采纳
    dongwei5794 dongwei5794 2013-11-02 07:37

    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>
    
    点赞 评论 复制链接分享
  • douyong5476 douyong5476 2013-11-02 07:37

    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
    
    点赞 评论 复制链接分享

相关推荐