WAP (wireless communication agreement) it is in the number mobile telephone, individual holds facility (PDA) reach the level of open sex whole world that news report has between the computer. Because WAP page of the static state is in,the service that a lot of respects cannot satisfy user individuation requests, because this passes WAP server to carry a language to produce dynamic WML page, have very extensive application value and very high commerce value.
WAP application structure special be similar to Internet, a typical WAP application request is such: Above all, the mobile terminal that has function of WAP user representative (WAP mobile phone) the small browser that moves through interior (Micro Browser) sends WAP to serve a request with wireless means to some website. This request is intercepted and capture by WAP gateway first, undertake coding compression to information content, in order to reduce network data flow, become HTTP agreement according to needing to change WAP agreement at the same time, transmit the request after processing corresponding WAP server next. Carry in WAP server, expand according to the page the property such as the name, the page that is requested direct or the output after carrying script to explain by the server, send an user via gateway again.
From afore-mentioned WAP application flow can see, the procedure that generates dynamic WAP page and webpage of dynamic generation Web is very similar. But because WAP applies use WML language to originate syntactic and strict XML, because this asks,the format of output must press the normative output of WAP webpage. In the meantime, the characteristic such as the soft hardware level that as a result of the application of WAP agreement limits, mobile client carries, have certain restriction to the format of the size of the page that outputs every time, image and capacity. We are with PHP script language below exemple, look how page of dynamic output WAP.
One, setting WEB server
Above all your Web server should install good PHP, can handle PHP script order namely. Next, wait for a file with processing PHP, WML, WBMP to make Web server can identify at the same time, the MIME watch of Web server needs to add kind of the following a few kinds of files.
Text/vnd.wap.wml.wml
Image/vnd.wap.wbmp.wbmp
Application/vnd.wap.wmlc.wmlc
Text/vnd.wap.wmls.wmls
Application/vnd.wap.wmlsc.wmlsc
2, output page of simple and dynamic WAP with PHP
There is a the simplest PHP to make the case of WAP page below. Because the attention needs PHP interpreter to explain this program, output WAP page, because this is all and similar,the program should be patulous name with.php.
< ? Php
Header(″ Content - Type: Text/vnd.wap.wml ″ ) ;
″ of <wml> <card> <p> of Echo (″ ) ;
L DS Of F Y H:i of ″ of Echo Date(: SA ″ ) ;
″ of </p></card></wml> of Echo (″ ) ;
? >
This example can be browsed in simulator of WAP mobile phone, export current date time, and cannot identify in common browser, can be considered as wrong download even. Because stated in program begin this output documentation is WML type,this is, this type has WAP to equipment can identify and explain only. Notable is, our common HTML language is lax to normative sex requirement, most browser can ” patient ” among them quite a few writes a mistake, and WML standard is quite rigid, a bit error is brought about possibly cannot output place to need a page.
Once we knew to output the standard process of WAP page with PHP script, we can use the function with powerful PHP to cooperate the simple script of the alternant processing with WML language and WML Script, development gives the applied system that suits us to need.
3, create image with PHP trends
WAP application uses a kind of special and black and white image format WBMP. We already will have image to be changed into WBMP format with a few tools, use in WML documentation next. But if make place can dynamicly,image needs to be like K line attempt to wait on WAP site, will have wide applied perspective. Fortunately, the GD library of PHP (version 1.8 above) had provided corresponding function.
< ? PHP
Header(″ Content - Type: Image/vnd.wap.wbmp ″ ) ;
Sim = ImageCreate(50, 50);
Swhite = ImageColorAllocate(Sim, 255, 255, 255);
Sblack = ImageColorAllocate(Sim, 0, 0, 0);
ImageRectangle(Sim, 5, 5, 20, 20, sblack);
ImageDestroy(Sim); of of ImageWBMP(Sim);
? >
This file will show casing of rectangle of a black in WAP simulator. The attention should use the image function warehouse of GD, must be in PHP configuration file of library of to load PHP_GD.DLL.
4, the Chinese character is handled in PHP
WAP serves as a kind of whole world application, chose UNICODE 2.0 to regard its as encode of standard character set, so that can be handled at the same time,include a variety of written languages such as English, Chinese, Japanese, French. And we handle what the Chinese character uses usually is GB2312 encode, certainly will of different internal code standard cannot general, so if do not have transition through stopwatch between two kinds of encode, pile up a phenomenon with respect to chaos of meeting occurrence Chinese character. There has been more mature GB now - the 2312 courses that change with UNICODE encode and function, use in the system such as ASP, PHP, JSP, we can go up in site of a few technologies find them.
Current most WAP mobile phone (Nokia7110, love establishs letter R320S to wait a moment) it is use UTF - of 8 encode, use UNICODE to code namely. Such, if we use Chinese character in WML directly (GB2312 codes) , will generate random code, mobile phone user cannot identify, so we are before output Chinese, want to use program or function to have the code of UNICODE to Chinese. And in the mobile phone that codes in GB2312 of a few support or WAP terminal unit, type hind can display the internal code that we can define nice documentation in the program correctly directly Chinese character, for example:
< ? Php
Header(″ Content - Type: Text/vnd.wap.wml; Charset=gb2312 ″ ) ;
″ of <wml><card><p> of Echo (″ ) ;
Chinese of Echo (″ checks ″ ) ;
″ of </p></card></wml> of Echo (″ ) ;
? >
