如何解析 html 文件中的 php 文件

how to parse php file inside of html file

有人可以帮我配置我的 httpd.conf 服务器文件,以便我可以将简单的 php 代码 运行 作为 .html 文件执行吗?

浏览器不输出任何内容或只是空白。 (例如)

php 版本 - 7.2.8 服务器版本 - Apache/2.4.34 (Fedora)

您应该将 html 文件保存为 php 格式或使用 .htaccess 将所有 .html 页面制作成 运行 为 .php 个文件:
第一种方式:

file.html most convert to file.php

你最运行你的网络服务,然后用逻辑地址打开你的文件 http://localhost/file.php

第二种方式: 在您网站的根目录下创建一个 .htaccess 文件并添加此行:

[Apache2 @Ubuntu/Debian: 使用这个指令]

AddType application/x-httpd-php .html .htm

或者,来自下面的评论:

AddType application/x-httpd-php5 .html .htm

如果您 运行ning PHP 作为 CGI(可能不是这种情况),您应该改为:

AddHandler application/x-httpd-php .html .htm 

Using .htaccess to make all .html pages to run as .php files

在您的项目目录中创建 .htaccess 文件并使用以下代码:

RewriteEngine On
RewriteRule index.html index.php

用您的脚本文件名替换索引