运行而不是PHP时会显示实际代码

时间:2013-12-13 21:12:56

标签: php text

我一直在读书,但是当我在浏览器中打开它们但是在线php编辑器上工作时,书中有一些似乎不起作用。你能帮助我纠正这些代码吗?

<html>
<head>
<title>listing 12-9</title>
</head>enter code here
<body>
<?php
    $Today = date("l F d, Y");
    print ("Today is $Today, I will check your diary...<br>\n");

    $diaryDate = date("d");

    if ($diaryDate==3) print ("you have a dinner date");
    else
    if ($diaryDate==10) print ("dentist appointment today");
    else
    if ($diaryDate==23) print ("have the day off!");
    else
    if ($diaryDate==29) print ("go to conference");
    else
    print ("You have no booked events today!");
?>
</body>
</html>

还有:

 <html>
    <head>
    <title>listing 12-8</title>
    </head>
    <body>
    <?php
        $Today = date ("l F d, Y");
        print ("Today is $Today, I will check your diary...<br>\n");

        $diaryDate = date ("d");

        switch($diaryDate)
        {
            case 3: print("you have a dinner date"); break;
            case 10: print("dentist appointment today"); break;
            case 23 : print("have the day off!"); break;
            case 29: print ("go to conference"); break;
            default: print("You have no booked events today!");
            }

    ?>
    </body></html>

由于

1 个答案:

答案 0 :(得分:1)

您需要运行本地Web服务器才能在本地计算机的浏览器中执行PHP。 PHP代码由服务器处理并为浏览器呈现,因此如果没有在本地计算机上运行PHP的Web服务器,它将无法呈现。

查看安装WAMP(适用于Windows)或MAMP(适用于Mac)。

这些文件还需要.php扩展名,即使它们主要是HTML内容。