简单的php程序不起作用


Simple php program doesn't work

<html>
 <head>
    <title>Roll Em!</title>
 </head>
 <body>
    <h1>Roll Em!</h1>
    <?php
    $roll = rand(1,6);
    print "You rolled a $roll";
    print "<br>";
    ?>
 </body>
</html>

这是一个非常简单的程序,但由于某种原因,它确实有效!它给出了这样的输出

 Roll Em!
"; ?>

唯一的错误是 <?php 之间的空格,但完整的代码应该是:

<html>
 <head>
    <title>Roll Em!</title>
 </head>
 <body>
    <h1>Roll Em!</h1>
    <?php
    $roll = rand(1,6);
    echo "You rolled a " . $roll;
    echo "<br>";
    ?>
 </body>
</html>

你不应该使用打印,echo 在几乎所有情况下都更好,你应该使用" .$string ."将变量粘贴到文本字符串中。

PHP 开始标记应该是:<?php - 没有空格。