如何将PHP代码/文件添加到HTML(.html)文件? [英] How do I add PHP code/file to HTML(.html) files?
问题描述
我无法在我的HTML页面中使用PHP。例如, index.html
。我尝试过使用两种方法:
<?内容?>
和
<?php内容>
这些都不起作用。我的服务器提供PHP,当我使用 .php
扩展名时,它可以正常工作。这是一个问题,还是必须更改 php.ini
中的偏好设置?
AddType application / x-httpd-php .htm .html
这将告诉Apache使用.htm处理文件或.html文件扩展名为PHP文件。
I can't use PHP in my HTML pages. For example, index.html
. I've tried using both:
<? contents ?>
and
<?php contents ?>
Neither of these work. My server offers PHP, and when I use a the .php
extension, it works properly. Is this a problem or do I have to change the preferences in php.ini
?
You can't run PHP in .html files because the server does not recognize that as a valid PHP extension unless you tell it to. To do this you need to create a .htaccess file in your root web directory and add this line to it:
AddType application/x-httpd-php .htm .html
This will tell Apache to process files with a .htm or .html file extension as PHP files.
这篇关于如何将PHP代码/文件添加到HTML(.html)文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!