【问题标题】:How do I have to configre XAMPP so that it executds <?php ... ?> in html documents? [duplicate]如何配置 XAMPP 以便它在 html 文档中执行 <?php ... ?> ? [复制]
【发布时间】:2020-07-09 22:50:44
【问题描述】:

我正在尝试让 XAMPP 的 Apache 执行嵌入在 HTML 文档中的 &lt;?php ... ?

<html>
<head><title>abc</title></head>
<body>

<?php
  echo("bla");
?>

</body>
</html>

但是,&lt;?php ... ?&gt; 部分并未“执行”并逐字传输到浏览器。

我想我必须更改一个配置文件才能执行该 php。

【问题讨论】:

  • 我假设您调用了您的文件 something.php 而不是 something.html
  • 它叫something.html
  • 您不能在以 .html 结尾的 html 页面中运行 PHP 将文件扩展名更改为 .php 请参阅问题顶部的第二个链接。
  • @Dlk 为什么他们不能将.html 文件作为 PHP 运行?
  • @Dlk 哦,他们当然可以 :) 查看第二个副本。

标签: php html xampp


【解决方案1】:

据我所知,XAMPP 已经包含 PHP,但除非您以 .php 结束脚本名称,否则它不太可能被 PHP 引擎处理。

如果您尝试在.html 文件中使用php,那么 尝试添加 .htaccess 文件或使用以下行更改 apache 配置:

AddHandler 应用程序/x-httpd-php .html

或者试试下面的,

停止apache服务,然后在c:\xampp\apache\conf\httpd.conf部分的c:\xampp\apache\conf\httpd.conf中添加一项更改...

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

重启apache!

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 2017-11-07
    • 1970-01-01
    • 1970-01-01
    • 2011-11-03
    • 2018-08-07
    • 2014-05-22
    • 1970-01-01
    • 1970-01-01
    • 2013-04-04
    相关资源
    最近更新 更多