The basics of WAP and PHP programming

Source: Internet
Author: User
Tags php software
The basics of WAP and PHP programming. after reading the basics of WAP and PHP programming, the development of WAP is inseparable from the foundation of WWW. after all, the establishment of the entire WAP protocol references the WWW model, as far as possible, the Internet standards and technologies are used. for example, WML language originated from HTML and XML, and WMLScript is similar to traditional scripting languages. Indeed, even if WAP is "> <LINKhre

The development of WAP is inseparable from its WWW. after all, the establishment of the entire WAP protocol references the WWW model and follows many Internet standards and technologies as much as possible, for example, WML is originated from HTML and XML, and WMLScript is similar to traditional scripting languages. Indeed, although WAP is a new term, it is inseparable from the traditional international Internet. in terms of structure, it is more technical.
  
As mentioned in the WAP protocol, the markup language used for WAP pages is WML. when advanced operations are required, such as using certain terminal resources, WMLScript can be used, these two languages are simple and can even be described as simple. in particular, they are almost powerless to perform database operations. this "defect" is incompatible with the broad business and application prospects of WAP, however, we are not powerless. due to the convergence of WAP and WWW, we can still use WWW technology and resources to solve database access problems, because after all, most databases are still in the wired network.
  
What is the combination of the most popular web programming language and database? I believe many people will name "PHP" and "MySQL. They are in the domain of WWW or wired Internet. because of their convenient use and powerful features, they are spread by name. can they serve WAP? The answer is yes. People who are not familiar with WAP or PHP may be puzzled. after all, in the traditional sense, PHP provides WWW content and services. can they be "compatible" with WAP?

PHP rough solution

After reading the introduction of WAP, we should begin to gradually understand why PHP can still serve WAP. PHP is different from HTML, WML, Javascript, and Java. it runs on the server, while Javascript and Java run on the browser. compared with WAP, WMLScript runs on the client, however, these languages can be easily combined with PHP.

PHP has great flexibility. In WWW, it can generate any HTML code or even Javascript code required. Similarly, in WAP, we can still use the dynamic and flexible features of PHP to generate arbitrary WML code, so that PHP can naturally serve WAP.
  
The reason why PHP is used to provide the WAP service is not only flexible, but also because PHP can easily use the database. Users can use PHP to access any database that supports ODBC standards, such as Oracle, Sybase, ms SQL, MySQL, dBase, and Informix. This meets the needs of WAP business.

In practice, you usually need to create a php file. when you send a request to the server to browse the php file, the server will generate the corresponding HTML or WML content according to the code in the file, and send it to the browser or WAP terminal.
To get information about PHP, go to the http://www.php.com.

PHP-WML

PHP's system platform, working method, and installation method are not discussed in this article. after all, our focus is on how PHP works with WAP. In general, to make PHP work, we need a Web server with a PHP module, or a server that supports PHP. Apache is the most popular Web server in the world. In addition, we also need to install PHP software and databases such as MySQL. for details, refer to relevant books or websites. Next we will discuss how to make PHP generate WML code.
  
In WWW, the first line of content produced by PHP is often: content-type: text/html
  
However, WAP terminals do not understand such titles. The unit for the WAP terminal to download from the server is Deck, and the unit for browsing is Card. generally, a Deck forms a WML file. For the WAP service, the PHP file usually needs to contain the following code:

Header ("Content-type: text/vnd. wap. wml ");
Echo "<xml version = \" 1.01 "> \ n"
Echo "<! DOCTYPE wml PUBLIC \ "-// WAPFORUM // dtd wml 1.1 // EN \" \ "http://www.wapforum.org//DTD//wml_1.1.xml\"> \ n ";

The above three lines of code generate the WML File (Deck) file header, so that the WAP terminal can identify whether the downloaded Deck is in the WML format, and then display the remaining Deck content.
  
The following is the simplest Deck, which displays "Hello World" on the WAP terminal ".

<? Xml version = "1.0" encoding = "ISO-8859-1"?> <! DOCTYPE wml PUBLIC "-// WAPFORUM // dtd wml 1.1 //" http://www.wapforum.org//DTD//wml_1.1.xml ">
</Xml>
<! -- Nokia Parser Info: Phone = Nokia 7110; Height = 90; Width = 130; CurrentDeckSize = 38; MaxDeckSize = 1600; CardsOnEachLine = 5; CardsVerticalGap = 30 -->
</Card id = "card1" ordered = "true" newcontext = "false">
<P align = "left">
Hello World
</P>
</Card>
</Wml>

The corresponding php file we created is as follows:

<? Php
Header ("Content-type: text/vnd. wap. wml ");
Echo "<? Xml version = \ "1.0 \"> \ n ";
Echo "<! DOCTYPE wml PUBLIC \ "-// WAPFORUM // dtd wml 1.1 // EN \" \ "http://www.wapforum.org//DTD//wml_1.1.xml\"> \ n ";
Echo "\ n ";
Echo "<! -- Nokia Parser Info: Phone = Nokia 7110; Height = 90; Width = 130; CurrentDeckSize = 38; MaxDeckSize = 1600; CardsOnEachLine = 5; CardsVerticalGap = 30 --> \ n ";
Echo "<card id = \" card1 \ "ordered = \" true \ "newcontext = \" false \ "> ";
Echo "<p align = \" left \ "> \ n ";
Echo "Hello World ";
Echo "</p> ";
Echo "</card> ";
Echo "</wml> ";
?>

We can save this file as index. php3. when the WAP terminal browses the website, the Web server automatically performs the following operations based on the index. the content of php3 generates the WML content listed above and sends it to the gateway for processing. After receiving the Deck, the WAP terminal displays "Hello World" on the screen.
  
The above is the simplest application of PHP in WAP. it only generates several lines of WML code and does not involve database access. In fact, the powerful functions of PHP can provide a wealth of services for WAP, and the most worth exploring is its powerful database support, which will be discussed in future articles.

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.