Developing dynamic WAP page _php based on PHP programming language

Source: Internet
Author: User
Tags character set php language php programming php programming language

Wen/Chengdu Yell


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


The application structure of WAP is very similar to the Internet, a typical WAP application request step is described as follows:

1. A mobile terminal (such as a WAP phone) with a WAP user agent function that sends a WAP service request to a Web site through an in-house micro-browser. This request is intercepted by WAP gateway, encoding the content of the information to reduce the traffic of network data, and convert the WAP protocol to HTTP protocol as needed.

2. The protocol transmits the processed request to the corresponding WAP server. On the WAP server side, according to the attributes such as the page extension, the requested page is exported directly or by the server-side script, and then passed back 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, since the WML language used in WAP applications originates from the strict syntax of XML, the required output format must be exported according to the specification of WAP Web pages. At the same time, because of the application scope of WAP protocol and the limitation of software and hardware configuration of mobile client, there are some restrictions on the size of each output page, the format and the capacity of the image. In this paper, the author will take the PHP language as an example, and the vast number of network program development enthusiasts to explore the dynamic output WAP page method and application.

Output a simple dynamic WAP page

Because the process of generating a WAP page is very similar to generating a typical Web page, the author introduces it through one of the simplest examples of WAP pages. But the caveat: because you need a PHP interpreter to interpret the program and output a WAP page, all similar programs should be "PHP" extensions.

< PHP

Header ("CONTENT-TYPE:TEXT/VND.WAP.WML"); To define the output document as a WML type

Echo ("");

Echo ("Hello WAP");

Echo ("");

?>

This example can be browsed in WAP phone simulator, output a classic "Hello WAP" statement, but in the ordinary Web browser is not recognized, the reason is very simple, at the beginning of the program declared that the output document is WML type, only WAP devices can recognize and explain. But another caveat: the common HTML language is not strict with the normative requirements, most browsers can "tolerate" the written error, but the WML specification is very strict, any error may result in the inability to output the required page.

Instance 1 dynamically generating images

The image used by WAP is a special black-and-white image format: WBMP. Developers can use some of the existing tools to convert generic images into wbmp formats and then use them in WML documents. However, if the required images can be generated dynamically in the WAP program (such as the K-line chart of the stock market), the program will have an extremely broad application prospect. PHP provides a powerful graphical rendering function, and the following example displays a black rectangular box in the WAP emulator.

(Note: To use the image Library of GD, you must load the PHP_GD in your PHP configuration.) DLL "library file. )

<? Php

Header ("Content-type:image/vnd.wap.wbmp"); Defines the output as an image format of wbmp

Sim = Imagecreate (50, 50);

Swhite = Imagecolorallocate (sim,255,255,255);

Sblack = Imagecolorallocate (sim,0,0,0);

Imagerectangle (Sim, 5, 5, Sblack,);

Imagewbmp (Sim);

Imagedestroy (Sim);

?>

Example 2 processing Chinese characters

As a global application protocol, WAP chooses Unicode 2.0 as its standard character set code, which can simultaneously deal with many languages, such as English, Chinese, Japanese and French. But developers daily processing of Chinese characters is GB2312 code, different internal code standards must not be universal, therefore, if not between the two codes through the conversion of code system, there will be the phenomenon of Chinese characters garbled. Most of the current WAP phones (Nokia7110, Ericsson R320s, and so on) are encoded using UTF-8 (Unicode). If you use the Chinese character (GB2312 code) directly in WML, it will produce garbled, causing the cell phone users to not recognize, so before the output of Chinese, you must use the program or function (about this class of PHP library, the network has a very many technologically mature products can be downloaded) Encodes Unicode in Chinese. In a few mobile phones or WAP terminals that support GB2312 encoding, the developer can display Chinese characters directly after defining the code type of the document in the program, and look at an example:

< PHP

Header ("CONTENT-TYPE:TEXT/VND.WAP.WML; charset=gb2312 "); Defines the encoding of the character as GB2312

Echo ("");

Echo ("Hello");

Echo ("");

?>

In the "header" Statement of the program, the encoding of the text is defined as GB2312, and if the user's phone supports GB2312 encoding, the words "Hello" will be displayed.

As the leading of network communication in the future, the development of WAP program is becoming more and more popular. I believe that through this reading, developers can use PHP for WAP development has a preliminary impression, I hope that the majority of readers in this article based on the WML language, the development of a more powerful WAP applications.


Mass Network report

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.