PHP 不执行 XAMPP (Windows)
PHP not executing with 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>
当我 select Apache 服务器中的文件时,只显示代码本身。我已经搜索了一段时间,但似乎找不到问题所在。提前致谢。
您的 PHP 代码没有执行,因为服务器将文件解释为文本文件,因此代码没有执行。这是因为您的文件名有 .txt 扩展名。
not sure how to get rid of the .txt suffix
使用 Notepad++ 等任何代码编辑器将文件另存为 PHP 文件,从而去掉 .txt 扩展名。
或者普通的Windows记事本,只需select另存为"all file",文件名确保只有"index.php".
(为澄清而编辑)我正在尝试使用 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>
当我 select Apache 服务器中的文件时,只显示代码本身。我已经搜索了一段时间,但似乎找不到问题所在。提前致谢。
您的 PHP 代码没有执行,因为服务器将文件解释为文本文件,因此代码没有执行。这是因为您的文件名有 .txt 扩展名。
not sure how to get rid of the .txt suffix
使用 Notepad++ 等任何代码编辑器将文件另存为 PHP 文件,从而去掉 .txt 扩展名。
或者普通的Windows记事本,只需select另存为"all file",文件名确保只有"index.php".