一篇介绍hawhaw及用它来做wap站的文章
看到有个需要就抽空写了一下。时间紧写的不好,希望有识之士能提出问题,共同研究。
我先发表到我的论坛:
http://yuelao.net/modules.php?name=...pic&p=3528#3528
,再转到这里来的。
现在要讨论的是
http://hawhaw.de
HAWHAW。DE 提供强大的类可以供PHP程序员较容易地编写WAP站点。
一次编写可让WEB程序运行多种浏览器XHTML, HDML, i-modeTM , MML, PDA's and voice browsers 。
HAWHAW sites are capable to serve XHTML, HDML, i-modeTM , MML, PDA's and voice browsers as well!
Since Version 5.0 HAWHAW additionally supports VoiceXML.
从5。0开始HAWHAW支持VoiceXML。即可内嵌声音。
现在开始编写WAP程序。
先下载hawhaw.inc
再新建个php文件,为
代码:
<?php
require("hawhaw.inc");
$myPage = new HAW_deck("Welcome");
$myText = new HAW_text("Hello WAP!");
$myPage->add_text($myText);
$myPage->create_page();
?>
保存为firstwap.php
然后用手机浏览http://yoursite.com/firstwap.php
你就会看到
Hello WAP!
如此简单,而且你也可以在IE窗口中打开。
HAWHAW的语法:
1。首先要导入hawhaw.inc,定义页面头。
代码:
// first we have to import the HAWHAW class library
require("../hawhaw.inc");
// Here we define a deck named "Demo" where all content should be centered
$DemoPage = new HAW_deck("Demo", HAW_ALIGN_CENTER);
2.添加粗体文字:
代码:
// We define our first line (with bold big characters)
$text1 = new HAW_text("Welcome to HAWHAW!", HAW_TEXTFORMAT_BOLD | HAW_TEXTFORMAT_BIG);
$DemoPage->add_text($text1);
3。添加空行:
代码:
// We add one blank line ...
$text2 = new HAW_text("");
$DemoPage->add_text($text2);
4。页面自动跳转语句:
代码:
// after 10 seconds we want to start with pass 2
$DemoPage->set_redirection(10, $_SERVER['PHP_SELF'] . "?pass=2");
5。如果机器不支持自动跳转功能,则这么写
代码:
// in case that the device does not support redirection:
// ... we define a link additionally
$link1 = new HAW_link("Continue", $_SERVER['PHP_SELF'] . "?pass=2", "Start");
$DemoPage->add_link($link1);
6。播放声音
代码:
// and we play link jingles for voice users
// ==> so they know that they can say 'Continue' to continue
$DemoPage->set_voice_jingle("jingle.wav");
7,增加超级链接
代码:
$link1 = new HAW_link("Example 1","e1.wml","Formats");
$linkset->add_link($link1);
8。页面收尾。必须!
代码:
// That's all! This command creates the appropriate markup language.
$DemoPage->create_page();
9。设置字体及颜色。(设置颜色,只对(X)HTML有效)
代码:
$myText1 = new HAW_text("Some text formats", HAW_TEXTFORMAT_BOXED);
$myText1->set_color("yellow", "#889988"); // works with (X)HTML only
$myText2 = new HAW_text("This is bold", HAW_TEXTFORMAT_BOLD);
$myText3 = new HAW_text("This is italic", HAW_TEXTFORMAT_ITALIC);
$myText4 = new HAW_text("Underlined", HAW_TEXTFORMAT_UNDERLINE);
$myText5 = new HAW_text("BIG", HAW_TEXTFORMAT_BIG);
$myText6 = new HAW_text("and very small", HAW_TEXTFORMAT_SMALL);
$myText7 = new HAW_text("And now a little bit of all", HAW_TEXTFORMAT_BOLD | HAW_TEXTFORMAT_UNDERLINE | HAW_TEXTFORMAT_ITALIC);
$myRule = new HAW_rule();
$myPage->add_text($myText1);
$myPage->add_text($myText2);
$myPage->add_text($myText3);
$myPage->add_text($myText4);
$myPage->add_text($myText5);
$myPage->add_text($myText6);
$myPage->add_rule($myRule);
$myPage->add_text($myText7);
$myPage->create_page();
10。添加文字表单:
代码:
$myForm = new HAW_form($_SERVER['PHP_SELF']);
$text = new HAW_text("Please enter some digits:");
$theID = new HAW_input("id", "", "Account", "*N");
$theID->set_size(4);
$theID->set_maxlength(4);
$thePW = new HAW_input("pw", "", "Password", "*N");
$thePW->set_size(4);
$thePW->set_maxlength(4);
$thePW->set_type(HAW_INPUT_PASSWORD);
$theSubmission = new HAW_submit("Submit", "submit");
$myForm->add_text($text);
$myForm->add_input($theID);
$myForm->add_input($thePW);
$myForm->add_submit($theSubmission);
$AuthPage->add_form($myForm);
$AuthPage->create_page();
11。添加多选表单
代码:
$myForm = new HAW_form($_SERVER['PHP_SELF']);
// tell voice users what this here is all about
$myForm->set_voice_text("Say yes or no to the following statements");
$cb1 = new HAW_checkbox("c1", "c", "2+3=6");
// speech synthesizers (like many people) have some problems with math terms
$cb1->set_voice_text("2 plus 3 is equal 6");
$cb2 = new HAW_checkbox("c2", "c", "SIN(PI)=0");
$cb2->set_voice_text("sinus of pee is equal 0");
$cb3 = new HAW_checkbox("c3", "c", "SQRT(16)=4");
$cb3->set_voice_text("squareroot of 16 is equal 4");
$sbt = new HAW_submit("Solution", "solution");
$myForm->add_checkbox($cb1);
$myForm->add_checkbox($cb2);
$myForm->add_checkbox($cb3);
$myForm->add_submit($sbt);
$CalcPage->add_form($myForm);
$CalcPage->create_page();
12。添加电话号码
代码:
$phone = new HAW_phone("+1 407 386 3678", "CALL");
$PhonePage->add_phone($phone);
13。制表格
代码:
$name_a = array("Peter", "Mary", "John", "Jane", "Norbert", "Sue", "Mike",
"Jenny", "Lloyd", "Tamara", "Ben", "Betty", "Tom", "Clara",
"Bob", "Ellen", "Rick", "Nicole", "Jack", "Liz", "Edward",
"Monica", "Bill", "Maria", "Pedro", "Nelly", "Ted", "Kitty",
"Andy", "Sabrina", "George", "", "", "", "");
$myCalendar = new HAW_table();
$headline = new HAW_row();
$fmt = HAW_TEXTFORMAT_SMALL | HAW_TEXTFORMAT_BOLD; // text format for headline
$monday = new HAW_text("M", $fmt); $headline->add_column($monday);
$tuesday = new HAW_text("T", $fmt); $headline->add_column($tuesday);
$wednesday = new HAW_text("W", $fmt); $headline->add_column($wednesday);
$thursday = new HAW_text("T", $fmt); $headline->add_column($thursday);
$friday = new HAW_text("F", $fmt); $headline->add_column($friday);
$saturday = new HAW_text("S", $fmt); $headline->add_column($saturday);
$sunday = new HAW_text("S", $fmt); $headline->add_column($sunday);
$myCalendar->add_row($headline);
for ($week = 0; $week < 5; $week++)
{
$line[$week] = new HAW_row();
for ($day = 0; $day < 7; $day++)
{
$i = $week * 7 + $day; // day index
$name = $name_a[$i];
$link[$i] = new HAW_link($i+1, $_SERVER['PHP_SELF'] . "?who=" . $name, $name);
if ($i < 31) $line[$week]->add_column($link[$i]);
else $line[$week]->add_column(); // make some empty cells
}
$myCalendar->add_row($line[$week]);
}
$myPage->add_table($myCalendar);
--------------------------------------------------------------------------------