Developing dynamic WAP pages in the PHP programming language

Source: Internet
Author: User
Keywords Developing dynamic WAP pages in the PHP programming language
Tags 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 communication, static WAP pages in many aspects can not meet the user's personalized requirements, so developers can use the WAP server, such as PHP to generate dynamic WML pages, to meet the needs of users.


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

1. Mobile Terminal with WAP user agent function (such as WAP mobile phone), send WAP service request to a website through a micro browser running inside. The request is intercepted by WAP Gateway, and the information content is encoded and compressed to reduce network data traffic, and the WAP protocol is converted to HTTP protocol.

2. The Protocol forwards the processed request to the appropriate WAP server. In the WAP server side, according to the page extension and other properties, the requested page is interpreted directly or by the server-side script output, and then passed back to the user through the gateway.

From the WAP application process described above, the generation of dynamic WAP pages is very similar to the process of generating web pages dynamically. However, because the WML language used by WAP applications comes from syntax-Strict XML, the format required for the output must be output in accordance with the specifications of the WAP Web page. At the same time, due to the application scope of WAP protocol and the limitation of software and hardware configuration of mobile client, there are certain limitations on the size of each output page, the format and the capacity of the image. This article 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 generic Web page, the author introduces it through an example of the simplest WAP page. However, as a reminder: because the PHP interpreter is required to interpret the program and output WAP pages, all similar programs should be "PHP" extension Oh.

< PHP

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

Echo ("");

Echo ("Hello WAP");

Echo ("");

?>

This example can be browsed in the 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 a WML type, only the WAP device can be recognized and interpreted. However, it is important to note that the common HTML language is not strict with the normative requirements, most browsers can "tolerate" to accept the writing errors, but the WML specification is very strict, any error can cause the output of the required page.

Example 1 generating images dynamically

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 to wbmp format and then use them in WML documents. However, if the desired image can be generated dynamically in the WAP program (such as the candlestick Chart of the stock market), the program will have a very wide application foreground. PHP provides powerful graphics rendering, and the following example displays a black rectangular box in the WAP simulator.

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

<? Php

Header ("Content-type:image/vnd.wap.wbmp"); The image format for defining the output is 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 encoding, capable of simultaneously processing English, Chinese, Japanese, French and many other languages. However, the daily processing of Chinese characters is GB2312 code, different internal code standards must not be universal, so, if not between the two coding through the conversion of code, will appear garbled Chinese characters phenomenon. Most of the current WAP phones (Nokia7110, Ericsson r320s, etc.) are encoded using UTF-8 (that is, Unicode). If you use Chinese characters (GB2312 encoding) directly in WML, it will result in garbled characters, which can cause the phone user not to recognize, so you must use the program or function (for PHP libraries of this class, there are many technically mature products available for download) before exporting Unicode encoding for Chinese. In a few mobile phones or WAP devices that support GB2312 encoding, developers simply need to define the document's internal code type in the program to display the Chinese characters directly and see an example:

< PHP

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

Echo ("");

Echo ("Hello");

Echo ("");

?>

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

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


Popular web News

  • Related Article

    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.