php php代码在xampp上不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15142426/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
php code not working working on xampp
提问by Omer Obaid
I am new in php field. i'm using xampp and it's on. and php also activated.
我是 php 领域的新手。我正在使用 xampp,它已开启。并且php也启动了。
i wrote this code
我写了这段代码
<!DOCTYPE html>
<html>
<body>
<?php
$x=5;
$y=6;
$z=$x+$y;
echo $z;
?>
</body>
</html>
The output window is empty. I don't know what the error is. Does anyone know the solution?
输出窗口是空的。我不知道错误是什么。有谁知道解决方案?
回答by Kamil
Answer based on comments.
根据评论回答。
PHP file must be interpreted by web server (in your case - apache with php extension, which is part of XAMPP), which executes PHP code and sends script output/result via http protocol to web browser.
PHP 文件必须由 Web 服务器解释(在您的情况下 - apache 带有 php 扩展名,它是 XAMPP 的一部分),它执行 PHP 代码并通过 http 协议将脚本输出/结果发送到 Web 浏览器。
To execute PHP script and show it's result you have to use HTTP, like this: http://localhost/doctrinetest/welcome.php.
为了执行PHP脚本,并显示它的结果,你必须使用HTTP,像这样:http://localhost/doctrinetest/welcome.php。
c:\xampp\htdocsdirectory is "served" at http://localhost/URL.
c:\xampp\htdocs目录在http://localhost/URL处“提供” 。
Opening that file via filesystem (not using apache server) will output blank page, because browser is not supposed to execute PHP. However, that blank page will contain your static HTML part of code.
通过文件系统(不使用 apache 服务器)打开该文件将输出空白页,因为浏览器不应该执行 PHP。但是,该空白页面将包含您的静态 HTML 代码部分。
It looks like, you dont understand how PHP works. You need to read some books about web fundamentals.
看起来,您不了解 PHP 的工作原理。您需要阅读一些有关网络基础知识的书籍。
Eventually you can visit http://thenewboston.orgor http://phpacademy.org- they have very good educational videos.
最后,您可以访问http://thenewboston.org或http://phpacademy.org- 他们有非常好的教育视频。
回答by Wiggler Jtag
Please google for: How to install XAMPP. When its done, open in browser
请谷歌搜索:如何安装 XAMPP。完成后,在浏览器中打开
http://localhost/
to see if it is working or not.
看看它是否有效。
This is not a real question, before asking something you should learn something.
这不是一个真正的问题,在问什么之前你应该学习一些东西。
回答by rekire
It seems that the file is not interpreted as PHP. Make sure that the file has the extension php.
该文件似乎没有被解释为 PHP。确保文件的扩展名为 php。
The reason why you don't see the php code is that the tags prevent that, but you should find them in the source code.
您看不到 php 代码的原因是标签阻止了这一点,但您应该在源代码中找到它们。
You should check that you access the file via http and not directly with the browser. So you should have something like http://localhost/script.phpin your address bar.
您应该检查您是否通过 http 而不是直接使用浏览器访问文件。所以你http://localhost/script.php的地址栏中应该有类似的东西。
Also make sure that you have somewhere in your apache config such lines:
还要确保您的 apache 配置中有这样几行:
#
# PHP-Module setup
#
LoadFile "C:/Program Files (x86)/www/php/php5ts.dll"
LoadModule php5_module "C:/Program Files (x86)/www/php/php5apache2_2.dll"
<FilesMatch "\.php$">
SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch "\.phps$">
SetHandler application/x-httpd-php-source
</FilesMatch>

