How do I add PHP code/file to HTML(.html) files?(如何将 PHP 代码/文件添加到 HTML(.html) 文件?)
问题描述
我不能在我的 HTML 页面中使用 PHP.例如,index.html
.我都试过了:
I can't use PHP in my HTML pages. For example, index.html
. I've tried using both:
<? contents ?>
和
<?php contents ?>
这些都不起作用.我的服务器提供 PHP,当我使用 .php
扩展名时,它可以正常工作.这是一个问题还是我必须更改 php.ini
中的首选项?
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
?
推荐答案
您不能在 .html 文件中运行 PHP,因为除非您告诉它,否则服务器不会将其识别为有效的 PHP 扩展.为此,您需要在您的 Web 根目录中创建一个 .htaccess 文件并将这一行添加到其中:
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
这将告诉 Apache 将具有 .htm 或 .html 文件扩展名的文件作为 PHP 文件处理.
This will tell Apache to process files with a .htm or .html file extension as PHP files.
这篇关于如何将 PHP 代码/文件添加到 HTML(.html) 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何将 PHP 代码/文件添加到 HTML(.html) 文件?


基础教程推荐
- Libpuzzle 索引数百万张图片? 2022-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- 在多维数组中查找最大值 2021-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01