Develop a dynamic WAP page with PHP programming language

xiaoxiao2021-03-06  42

WAP (Wireless Communication Protocol) is an open global standard protocol that communicates between digital mobile phones, personal handheld devices (PDAs, etc.) and computers. With the continuous development of wireless communications, static WAP pages can not meet user personalized requirements in many ways, so developers can use the WAP server to use a dynamic WML page such as PHP, to meet the needs of users.

WAP's application structure is very similar to the Internet, and a typical WAP application request step is as follows:

1. Mobile terminals (such as WAP phones) with WAP user proxy function, send WAP service requests to a website via the internal running microwser. The request is intercepted by the WAP gateway, encoding the information content to reduce network data traffic, and convert the WAP protocol to the HTTP protocol as needed.

2. The protocol will transfer the processed request to the corresponding WAP server. In the WAP server side, according to the attributes such as page extensions, the requested page is directly output from the server-side script, and then the gateway is passed back to the user.

From the above WAP application process, it can be found that the generation of dynamic WAP pages and dynamically generated web pages are very similar. However, since the WAP application used by WAP applications from syntax strict XML, the format required to output must be output according to the specification of the WAP page. At the same time, due to the application range of the WAP protocol and the Software, hardware configuration, the size, the size, and capacity of the image, the format and capacity of the image are constantly restricted. This article will use the PHP language as an example, and the majority of network program development enthusiasts discuss the method and application of the dynamic output WAP page.

Output simple dynamic WAP page

Since the process of generating the WAP page is very similar, the author introduces the most simple WAP page example. However, remind: Since the PHP interpreter is required to explain the program and output the WAP page, all similar programs should be extended as "PHP".

Header ("Content-Type: Text / VND.WAP.WML"); // Defines the output document to WML type

Echo ("");

Echo ("Hello WAP");

Echo ("");

?>

This example can be browsed in the WAP mobile emulator, output a classic "Hello WAP" statement, but in a normal web browser is unrecognized, the reason is very simple, declare the output document is WML type in the beginning, Only WAP devices can identify and explain. However, it is necessary to remind: common HTML language is not strict, most browser can "tolerate" to receive errors, but WML's specification is quite strict, any error may result in unable to output it. page.

Example 1 Dynamically generated image

The image used by WAP is a special black and white image format: WBMP. Developers can use some existing tools to convert general images into WBMP format and then used in WML documents. But if you can dynamically generate the desired image (such as the stock market) in the WAP program, the procedure will have an extremely vast application prospect. PHP provides a powerful graphics drawing, the following instance will display a black rectangle in the WAP emulator.

(Note: To use the GD image function library, you must load the "php_gd.dll" library file in the PHP configuration.)

Header ("content-type: image / vnd.wap.wbmp"); // Defines the output of the output is 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);

?>

Example 2 Handling Chinese characters

As a global application, WAP selects Unicode 2.0 as its standard character set encoding, can handle multiple texts such as English, medium, days, and law at the same time. However, the Chinese characters of the developer's daily treatment are GB2312 encoding. Different internal code standards must not be universal, so if they are not converted between the two codes, Chinese characters garbled will occur. Most WAP phones (NOKIA7110, Ericsson R320S, etc.) are encoded using UTF-8 (ie unicode). If you use Chinese characters directly (GB2312 encoding) directly in WML, there will be garbled, causing mobile phone users unrecognizable, so before outputting Chinese, programs or functions must be used (regarding this PHP function library, there are very many technologies on the network) Mature products can be downloaded to Chinese in Chinese. In a few mobile phone or WAP terminal devices encoded by a few support GB2312, the developer can directly display the Chinese characters directly after defining the internal code type of the document in the program, see an instance:

Header ("content-type: text / vnd.wap.wml; charset = GB2312"); / / Define the code to GB2312

Echo ("");

echo ("Hello");

Echo ("");

?>

In the "Header" statement of the program, the code is defined to GB2312, if the user's mobile phone supports GB2312 encoding, will display "Hello" words.

As the dominant network communication, the development of WAP programs has become increasingly popular. I believe that by reading this article can make developers have a preliminary impression on WAP development using PHP. I hope that the readers can refer to the WML language on the basis of this article.

Excerpt from:

Sina Technology

转载请注明原文地址:https://www.9cbs.com/read-112371.html

New Post(0)