寫PHP/WML代碼
現在我們寫首個PHP/WML頁面,名字為index.wml
<?php
Header("Content-type: text/vnd.wap.wml");
Header("Cache-Control: no-cache, must-revalidate");
Header("Pragma: no-cache");
echo ("<?xml version='1.0'?>");
?>
"http://www.wapforum.org/DTD/wml_1.1.xml" >
<WML>
<CARD id=card1 title=UNITO/Database><P>
You can search for professors' consulting hours or for examinations timetables.
<SELECT name=choice title=Research value="1"> <OPTION selected value=exams_data>Examinations timetables</OPTION> <OPTION value=consulting_data>Consulting hours</OPTION></SELECT>
<DO type="text" label="Go">
<GO href="index2.wml#card2" method="get">
<POSTFIELD value="$(choice)" name="choice">
</GO>
</DO>
</P>
</CARD>
</WML>
第一行告訴浏覽器該文件的MIME類型,如果沒有頭文件的話,浏覽器是不懂得接收的是屬於什麼類型的內容,而且有了這一行的話,文件的擴展名就不重要了。對於你想寫一個多樣式的頁面,這個功能是十分有用的,你可以通過一個腳本來檢測設備或者它的性能,然後根據浏覽器的類型返回WML或者HTML。
檢查PHP是否已經裝有短標簽支持。如果是的話,你可以做一個類似<?xml version='1.0'?>的聲明,並且將它嵌套到PHP代碼中以免混淆。
該頁面的余下代碼只是讓你搜索測驗的時間或者咨詢的時間。選擇的項目會記錄在$choice變量中。
下一頁稱為index2.wml,讓你選擇是通過科目還是姓來查詢數據庫。
Header("Content-type: text/vnd.wap.wml");
Header("Cache-Control: no-cache, must-revalidate");
Header("Pragma: no-cache");
echo ("<?xml version='1.0'?>");
?>
"http://www.wapforum.org/DTD/wml_1.1.xml" >
<WML>
<CARD id=card2 title="Kind of research">
<P><BR><?php
echo ("You are checking ");
if ($choice == "exams_data") {
echo (" examinations timetables.<BR>n");
} else if ($choice == "consulting_data") {
echo (" consulting hours.<BR>n"); <BR>} else { <BR>echo ("I don't know what and there is some problem.<BR>n");
}
?>
<P><BR>You can search by surname (either exact or partial) or by subject (either exact or partial).<BR><BR>Select the kind of research. <BR><P>
<SELECT name="<?php echo (" $choice?);<br> ?>" value="surname" title="research"> <OPTION selected value=surname>professor's name</OPTION> <OPTION value=subject>subject</OPTION>