Use PHP programming language to develop dynamic WAP pages. Chengdu yellWAP (wireless communication protocol) is an open global standard protocol for communications between digital mobile phones, personal handheld devices (PDAs), and computers. With the continuous wireless communication/Chengdu yell
WAP (Wireless communication protocol) is an open global standard protocol for communications between digital mobile phones, personal handheld devices (PDAs), and computers. With the continuous development of wireless communication, static WAP pages cannot meet user personalized requirements in many aspects. Therefore, developers can use languages such as PHP on the WAP server to generate dynamic WML pages, to meet user needs.
The WAP application structure is very similar to the Internet. a typical WAP application request procedure is described as follows:
1. a mobile terminal (such as a WAP mobile phone) with the WAP user proxy function sends a WAP service request to a website through a micro browser running internally. This request is first intercepted by the WAP gateway and encoded and compressed to reduce network data traffic. at the same time, the WAP protocol is converted to the HTTP protocol as needed.
2. the protocol transfers the processed requests to the corresponding WAP server. On the WAP server side, the requested page is directly interpreted by the server script based on the page extension and other attributes, and then output to the user through the gateway.
From the above WAP application process, we can find that the process of generating dynamic WAP pages is very similar to that of dynamically generating Web pages. However, because the WML language used by the WAP application comes from the strict XML syntax, the output format must be output according to the WAP webpage specification. At the same time, due to the application scope of the WAP protocol and the software and hardware configurations of the mobile client, the size of the page output each time, the format and capacity of the image are limited. In this article, I will take the PHP language as an example to discuss with the majority of network programming enthusiasts how to dynamically output WAP pages and applications.
Outputs a simple dynamic WAP page
The process of generating a WAP page is very similar to that of creating a general Web page. I will introduce it through a simple WAP page example. However, I would like to remind you that the PHP interpreter is required to interpret the program and output the WAP page. Therefore, all similar programs should use the "php" extension.
<? Php
Header ("Content-type: text/vnd. wap. wml"); // defines that the output document is of the WML type.
Echo ("");
Echo ("Hello WAP ");
Echo ("");
?>
This instance can be viewed in the WAP mobile phone simulator and output a classic "Hello WAP" statement, but it cannot be identified in a common Web browser. The reason is very simple, this output document is declared at the beginning of the program as the WML type. only the WAP device can recognize and interpret it. However, I would like to remind you that common HTML languages do not have strict compliance requirements. most browsers are "tolerant" to accept the compilation errors, but WML standards are quite strict, any errors may cause failure to output the required page.
Instance 1 dynamically generates images
The image used by WAP is a special black/white image format: WBMP. Developers can use some existing tools to convert general images into WBMP format and then use them in WML documents. However, if the required image (such as the stock market's K-line chart) can be dynamically generated in the WAP program, the program will have a very broad application prospect. PHP provides a powerful graphic rendering function. the following example shows a black rectangle in the WAP simulator.
(Note: to use the GD Image function library, you must load the "PHP_GD.DLL" library file in the PHP configuration .)
<? PHP
Header ("Content-type: image/vnd. wap. wbmp"); // defines the output image format as WBMP.
Sim = ImageCreate (50, 50 );
Swhite = ImageColorAllocate (Sim, 255,255,255 );
Sblack = ImageColorAllocate (Sim, 0, 0 );
ImageRectangle (Sim, 5, 5, 20, 20, Sblack );
ImageWBMP (Sim );
ImageDestroy (Sim );
?>
Instance 2 processes Chinese characters
As a global application protocol, WAP uses UNICODE 2.0 as its standard character set encoding, and can simultaneously process English, Chinese, Japanese, and French texts. However, the Chinese characters processed by developers on a daily basis are GB2312 encoding. different internal code standards must not be universal. Therefore, if there is no conversion between the two types of codes, Chinese characters may be garbled. Currently, most WAP phones (Nokia7110, Ericsson R320S, etc.) are encoded using UTF-8 (UNICODE. If you use Chinese characters (GB2312 encoding) directly in WML, garbled characters will be generated, which cannot be identified by mobile users. Therefore, before outputting Chinese characters, you must use a program or function (for such PHP function libraries, many technically mature products on the network can be downloaded) to encode Chinese characters in UNICODE. In a few mobile phones or WAP terminal devices that support GB2312 encoding, developers only need to define the document's internal code type in the program to directly display Chinese characters. See an example:
<? Php
Header ("Content-type: text/vnd. wap. wml; charset = gb2312"); // defines the character encoding as GB2312
Echo ("");
Echo ("Hello ");
Echo ("");
?>
In the program's "header" statement, the text encoding is defined as GB2312. if your mobile phone supports GB2312 encoding, the "Hello" text will be displayed.
As the leader of network communication in the future, WAP program development has become increasingly popular. I believe that through reading this article, developers will have a preliminary impression on using PHP for WAP development. I hope that readers can refer to the WML language on the basis of this article, develop more powerful WAP applications.
Public network news
Yell WAP (Wireless communication protocol) is an open global standard protocol for communications between digital mobile phones, personal handheld devices (PDAs), and computers. As wireless communication continues...