Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么我的PHP代码不能工作?_Php_Html - Fatal编程技术网

为什么我的PHP代码不能工作?

为什么我的PHP代码不能工作?,php,html,Php,Html,我只是想知道为什么这个代码不起作用,提前谢谢。我是新来的,所以请不要因此而恨我 <html> <head> <h1> Hey! </h1> </head> <body> <p> <?php ran = rand(0, 5); if ($ran != 2){ echo "hi"; }

我只是想知道为什么这个代码不起作用,提前谢谢。我是新来的,所以请不要因此而恨我

<html>
  <head>
  <h1> Hey! </h1>
  </head>
  <body>
    <p>
      <?php
        ran = rand(0, 5);
            if ($ran != 2){
            echo "hi";
            }
            else{
                echo "wow";
            }
      ?>

    </p>
  </body>
</html>
换成

$ran = rand(0, 5);

您的计算机上安装了PHP吗?您不能只从浏览器运行PHP文件,必须安装XAMPP或WAMP之类的软件,或者至少安装PHP,并设置允许浏览器处理PHP的路径


只要您能够在浏览器中查看PHP文件,文件扩展名为.PHP,并且在运行之前添加$BEFOR,就不会有问题。

这不是PHP。这就是HTMLW当你运行它时会发生什么?输出?不使用美元。ran=rand0,5;需要为$ran=rand0,5;替换ran=rand0,5;至$ran=rand0,5;文件的扩展名是.php而不是.html吗?它仍然不起作用:/运行脚本时的输出是什么..?请不要用firefox运行它,但输出只是嘿!您运行的文件末尾是否有.php?是否为.html。。?因为如果最后是its.html,它将无法到达php代码。确保它以.php扩展名结尾…doneIt是html,但我将它改为.php。它仍然有相同的输出下载XAMPP从。它是可安装的,并且包含您在本地使用PHP所需的所有内容。我可以改用adobe dreamweaver吗?不。您仍然需要安装PHP。很抱歉,这是无法避免的。
$ran = rand(0, 5);