php - 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 服务器中选择文件时,只会显示代码本身。我已经搜索了一段时间,但我似乎无法找到问题所在。提前致谢。
解决方案
您的 PHP 代码未执行,因为服务器将文件解释为文本文件,因此代码未执行。这是由于您的文件名具有 .txt 扩展名。
not sure how to get rid of the .txt suffix
使用 Notepad++ 等任何代码编辑器将文件保存为 PHP 文件,从而摆脱 .txt 扩展名。
或者对于普通的Windows记事本,只需选择另存为“所有文件”,文件名确保只有“index.php”。
推荐阅读
- php - Laravel 在 90 天后更改日期上的状态
- google-apps-script - 在谷歌表格中使用过滤器/查询时自动 S# 列
- django - Viewset/Serializer 上的 DRF PUT 不会在模型实例上触发 post_save 信号
- java - 我怎样才能在 Selenide 上做这个方法
- excel - Powershell 数据处理
- regex - 我想通过更改特定位置的一个字符来批量编辑数百个文件
- python - postman 中的 Runner 集合与 Python 代码之间的关系
- php - Symfony 5 获取 @ParamConverter 注释未找到的失败对象
- ruby-on-rails - Rails 从 start_date 和 end_date 计算日期持续时间
- r - Rcpp 函数导致包崩溃