明輝手游網(wǎng)中心:是一個(gè)免費(fèi)提供流行視頻軟件教程、在線學(xué)習(xí)分享的學(xué)習(xí)平臺(tái)!

創(chuàng)建動(dòng)態(tài)的WML網(wǎng)站(二)

[摘要]寫PHP/WML代碼   現(xiàn)在我們寫首個(gè)PHP/WML頁面,名字為index.wml <?php Header("Content-type: text/vnd.wap.wml"); Header("Cache-Control: no-cache, must-...
寫PHP/WML代碼

  現(xiàn)在我們寫首個(gè)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類型,如果沒有頭文件的話,瀏覽器是不懂得接收的是屬于什么類型的內(nèi)容,而且有了這一行的話,文件的擴(kuò)展名就不重要了。對(duì)于你想寫一個(gè)多樣式的頁面,這個(gè)功能是十分有用的,你可以通過一個(gè)腳本來檢測(cè)設(shè)備或者它的性能,然后根據(jù)瀏覽器的類型返回WML或者HTML。

  檢查PHP是否已經(jīng)裝有短標(biāo)簽支持。如果是的話,你可以做一個(gè)類似<?xml version='1.0'?>的聲明,并且將它嵌套到PHP代碼中以免混淆。

  該頁面的余下代碼只是讓你搜索測(cè)驗(yàn)的時(shí)間或者咨詢的時(shí)間。選擇的項(xiàng)目會(huì)記錄在$choice變量中。
下一頁稱為index2.wml,讓你選擇是通過科目還是姓來查詢數(shù)據(jù)庫(kù)。


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>