【问题标题】:How do I run PHP in HTML?如何在 HTML 中运行 PHP?
【发布时间】:2011-09-13 12:35:08
【问题描述】:

如果我有一个文件 file.php,与 index.html 位于同一目录中:

文件.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 中?

【问题讨论】:

标签: php html embed embedding


【解决方案1】:

这对我有用:

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

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

【讨论】:

  • 无论出于何种原因,这让 Chrome 想要下载该网页
  • 似乎顺序很重要,这是一个有效的:AddHandler application/x-httpd-php .htm .htmlAddType application/x-httpd-php .htm .html
【解决方案2】:

将index.html 重命名为index.php,并填写以下内容:

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

【讨论】:

  • PHP 可以在 .html 文件中运行(使用 mod_php 和 fpm),请参阅下面的评论
猜你喜欢
  • 2014-05-16
  • 1970-01-01
  • 2018-07-20
  • 2020-10-17
  • 2013-10-22
  • 1970-01-01
  • 2016-08-19
  • 1970-01-01
  • 2017-03-12
相关资源
最近更新 更多