首页 > 解决方案 > PHP 不使用 XAMPP (Windows) 执行

问题描述

(为澄清而编辑)我正在尝试使用 XAMPP 中的 Apache Web 服务器在名为“index.php”的文件中执行一些 PHP 代码。该文件位于 C:\xampp\htdocs\index.php.txt (不知道如何摆脱 .txt 后缀)。我通过在浏览器中输入“ http://localhost/index.php.txt ”来访问该文件。代码是:

<!DOCTYPE html>
<html>
<body>
      <?php echo "It works!"; ?>
</body>
</html>

当我在 Apache 服务器中选择文件时,只会显示代码本身。我已经搜索了一段时间,但我似乎无法找到问题所在。提前致谢。

标签: phpsql-serverapachexampp

解决方案


您的 PHP 代码未执行,因为服务器将文件解释为文本文件,因此代码未执行。这是由于您的文件名具有 .txt 扩展名。

not sure how to get rid of the .txt suffix

使用 Notepad++ 等任何代码编辑器将文件保存为 PHP 文件,从而摆脱 .txt 扩展名。

或者对于普通的Windows记事本,只需选择另存为“所有文件”,文件名确保只有“index.php”。


推荐阅读