PHP Generate WML Page Method _php Tutorial

Source: Internet
Author: User
Tags echo date
Because the static WAP page can not satisfy the user's personalized service request in many aspects, the dynamic WML page is generated through the WAP server language, which has a wide application value and high commercial value.
WAP application structure is very similar to the Internet, a typical WAP application request is this: first, a WAP user agent function of mobile terminals (WAP phones, etc.) through the internal running micro-browser (micro Browser) to a website wirelessly send WAP service requests. The request is intercepted by the WAP gateway, the information content is encoded compressed to reduce the network data traffic, and as needed, the WAP protocol is converted to the HTTP protocol, and then the processed request is forwarded to the corresponding WAP server. On the WAP server side, depending on the nature of the page extension, the requested page is interpreted directly or by the server-side script and then returned to the user via the gateway.
As you can see from the WAP application process described above, generating a dynamic WAP page is very similar to the process of generating a Web page 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, the level of hardware and software of mobile clients, the size of each output page, the format and capacity of the image are limited. Let's take the PHP scripting language as an example to see how to dynamically output WAP pages. In. National Webmaster Station
First, set up a Web server
First of all, your Web server will be able to handle PHP scripts by installing PHP. Second, to enable the Web server to identify and process PHP, WML, wbmp and other files, the Web server's MIME table needs to add the following file types.
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
Second, with PHP output simple dynamic WAP page www^chinaz^com
Here is an example of the simplest PHP-generated WAP page. Note that the PHP interpreter is required to interpret the program and output WAP pages, so all similar programs should have a. php extension.
Header (″content-type:text/vnd.wap.wml″);
Echo (″
″);
echo Date (″l DS of F Y h:i:s A″);
Echo (″
″);
?>
This example can be browsed in the WAP phone simulator, output the current date and time, not recognized in the normal browser, or even be considered as a wrong download. This is because the output document is declared as a WML type at the beginning of the program, and only the WAP device is able to recognize and interpret the type. It is important to note that our common HTML language is not strict with the normative requirements, most browsers can "tolerate" a considerable number of written errors, and the WML specification is very strict, a bit of error can result in the output of the required page.
Once we know the standard procedure for outputting WAP pages with PHP scripts, we can use PHP's powerful capabilities to work with the interactive processing of WML languages and the simple scripting of WML scripts to develop the application system that suits our needs.
Third, dynamic generation of images with PHP
WAP applications use a special black and white image format wbmp. We can use some tools to convert an existing image into a wbmp format, which is then used in a WML document. However, in the WAP site, if you can dynamically generate the required images such as Candlestick chart, there will be a broad application prospects. Fortunately, the PHP GD library (version 1.8 and above) has provided the appropriate functions.
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, +, sblack);
Imagewbmp (Sim); Imagedestroy (Sim);
The file will display a black rectangular box in the WAP simulator. Note To use the image Library of GD, PHP_GD must be loaded in the PHP configuration. DLL library file.
Iv. working with Chinese characters in PHP
WAP, as a global application, chooses Unicode 2.0 as its standard character set encoding so that it can handle many languages including English, Chinese, Japanese, and French. And we usually deal with the use of Chinese characters is GB2312 code, different internal code standard is bound to not be universal, so if not between the two encodings through the Code table conversion, will appear garbled characters phenomenon. Now there are more mature GB-2312 and Unicode encoding programs and functions, and used in ASP, PHP, JSP and other systems, we can find them on some technical sites. Www^chinaz^com
Most of the current WAP phones (Nokia7110, Ericsson r320s, etc.) are encoded using UTF-8, which is encoded using Unicode. Thus, if we use the Chinese character (GB2312 encoding) directly in WML, it will be garbled and the phone user cannot recognize it, so we will use the program or function to encode the Chinese Unicode before exporting it. In a few mobile phones or WAP devices that support GB2312 encoding, we can display Chinese characters directly after we define the code type of the document in the program, for example:
Header (″CONTENT-TYPE:TEXT/VND.WAP.WML; charset=gb2312″);
Echo (″″);
Echo (″ Chinese test ″);
Echo (″″);
?>

http://www.bkjia.com/PHPjc/320402.html www.bkjia.com true http://www.bkjia.com/PHPjc/320402.html techarticle since the static WAP page can not meet the user's personalized service request in many aspects, the dynamic WML page is generated by the WAP server-side language, which has a wide application value and high ...

  • 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.