我一直在研究一本書,但本書中有幾篇文章似乎並不工作,當我在瀏覽器中打開它們,但是在線php編輯器上工作時。你們能幫我糾正代碼嗎?運行代碼時出現實際代碼而不是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>
感謝
你使用的是什麼文件名?你給他們的.php擴展名?你是通過網絡服務器運行它們,還是直接在瀏覽器中打開文件? – andrewsi
文件名是列表12-9和列表12-8。以前使用list12-6的工作已經開始。兩者都有HTML擴展,我使用xampp和使用本地主機來打開文件 – user3100858
它們必須具有.php擴展名,即使它們大部分是HTML。 – Ennui