2011-06-12 29 views
3

如果我有一個文件,file.php,在同一個目錄中的index.html:如何在HTML中運行PHP?

file.php:

<?php 
echo "<body><img src=\"hi.jpg\" /><br /><p>I was here</p>" 
?> 

的index.html:

<html> 
<head></head> 
<!-- I want to enter the PHP in file.php here --></body> 
</html> 

我如何把file.php放在index.html中?

+0

這是非常類似的問題http://stackoverflow.com/questions/6065494/php-website-one-page-for-design/6065573#6065573,它已被回答。 – Luke 2011-06-12 19:24:32

回答

9

重命名index.htmlindex.php,並用以下填充:

<html> 
<head></head> 
<?php 
require('./file.php'); 
?> 
</html> 
+0

PHP可以在.html文件中運行(都使用mod_php和fpm),請參閱下面的註釋 – frinux 2016-10-26 13:40:48

2

這爲我工作:

以下內容添加到您的.htaccess文件

AddType application/x-httpd-php .php .htm .html 
AddHandler application/x-httpd-php5 .html .php .htm 
+1

無論出於何種原因,這使Chrome想要下載網頁 – 2014-04-15 18:14:16

+1

看起來命令很重要,這裏是一個工作的: 'AddHandler application/x-httpd-php .htm .html' 'AddType application/x-httpd-php .htm .html' – frinux 2016-10-26 13:39:27