Learn more about PHP Web server _php Tutorial

Source: Internet
Author: User
Tags echo date php web server
We all know the power of PHP, recently saw the knowledge of the PHP Web server, we will discuss this issue with you. WAP (Wireless Communication Protocol) is an open global standard for communication between digital mobile phones, personal handheld devices (PDAs, etc.) and computers. 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.

First, set up a PHP Web server

First of all, your Web server will be able to handle PHP scripts by installing PHP. Second, in order to enable the PHP Web server to identify and process PHP, WML, wbmp and other files, the Web server MIME table needs to add the following file types.

 
  
  
  1. TEXT/VND.WAP.WML. WML
  2. Image/vnd.wap.wbmp. wbmp
  3. APPLICATION/VND.WAP.WMLC. WMLC
  4. Text/vnd.wap.wmls.wmls
  5. APPLICATION/VND.WAP.WMLSC. WMLSC

Second, with PHP output simple dynamic WAP page

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.

 
 
  1. php
  2. Header (″content-type:text/vnd.wap.wml″);
  3. Echo (″<WML> <card> < p > ″);
  4. echo Date (″l DS of F Y h:i:s A″);
  5. Echo (″ p> card > WML > ″);
  6. ?>

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 S cript 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.

 
 
    1. !--? php
    2. Header (″content-type:image/vnd.wap.wbmp″);
    3. sim = imagecreate (50, 50);
    4. swhite = imagecolorallocate (sim,255,255,255);
    5. sblack = imagecolorallocate (sim,0,0,0);
    6. Imagerectangle (Sim, 5, 5, +, sblack);
    7. imagewbmp (Sim); Imagedestroy (Sim);
    8. "

The file will display 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 Web server 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.

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:

 
 
  1. Php 
  2. header (″CONTENT-TYPE:TEXT/VND.WAP.WML; CharSet = gb2312 ″);
  3. Echo (″<WML><card><P >″);
  4. Echo (″ Chinese test ″);
  5. Echo (″ p> card > WML > ″);
  6. ?>

http://www.bkjia.com/PHPjc/446475.html www.bkjia.com true http://www.bkjia.com/PHPjc/446475.html techarticle we all know the power of PHP, recently saw the knowledge of the PHP Web server, we will discuss this issue with you. WAP (Wireless Communication protocol) is ...

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