Home php教程 php手册 WAP与PHP程序设计之基础篇

WAP与PHP程序设计之基础篇

Jun 21, 2016 am 09:00 AM
echo php wap

  WAP的发展离不开其WWW的底蕴,毕竟,整个WAP协议的制定参照了WWW的模型,并且尽可能地沿用了Internet的诸多标准和技术,如WML语言脱胎于HTML与XML,WMLScript与传统的脚本语言也很相似。的确,WAP虽然是个新名词,但是它却与传统的国际互联网密不可分地结合着,在结构上如此,在技术上更是如此。
  
  在WAP协议中提到WAP页面所使用的标记语言为WML,当需要进行较高级的操作,如使用终端机的某些资源时,可以使用WMLScript脚本语言,这两种语言很简单,甚至可以用简陋来形容,特别是它们对数据库的操作几乎无能为力,这种"缺陷"与WAP广阔的商务和应用前景格格不入,但我们并不是无能为力的,由于WAP和WWW的交融,我们仍然可以使用WWW的技术与资源来解决数据库的访问问题,因为毕竟多数数据库仍处于有线网络内。
  
  目前最流行的网页编程语言和数据库的搭配是什么?相信很多人会说出"PHP"与"MySQL"这两个名字。它们属于WWW或者有线互联网的范畴,由于使用方便与功能强大的特点而美名传播,那么它们能够为WAP服务吗?答案是肯定的。不熟悉WAP或者PHP的人或许有些不解,毕竟在传统意义上PHP提供的是WWW的内容与服务,对于WAP,它们能"兼容"吗?

  PHP粗解

  看了WAP的介绍,大家应该开始逐步理解PHP为何仍能为WAP服务了。PHP与HTML、WML、Javascript、Java都不一样,它是在服务器端运行的,而Javascript、Java等都运行在浏览器端,相对于WAP,WMLScript运行于客户机端,但是,以上的这些语言都可以很容易与PHP结合起来。   

  PHP具有很大的灵活性,在WWW中,它可以生成所需要的任何HTML代码,甚至Javascript代码。同样,在WAP中,我们仍然可以利用PHP这种动态、灵活的特点,生成任意的WML代码,这样,PHP自然能够为WAP服务。   
  
  之所以使用PHP来提供WAP服务,除了它灵活的特点外,还由于PHP可以方便的使用数据库。用户可以使用PHP存取Oracle、Sybase、MS SQL、MySQL、dBase、Informix等任何支持ODBC标准的数据库,这点正好迎合了WAP商务的需求。   

  在实用中,一般需要建立PHP文件,当用户向服务器发出浏览该PHP文件的请求时,服务器将根据文件中的代码产生相应的HTML或WML内容,并发送给浏览器或WAP终端。   
  如想获取关于PHP的信息,可以前往http://www.php.com查看。

  PHP-WML

  PHP的系统平台、工作方式、安装方法,这些都不在本文的讨论范围内,毕竟我们的重点是PHP如何与WAP协作。一般而言,为了能让PHP工作,我们需要带有PHP模块的Web服务器,或者说支持PHP的服务器,Apache是世界上最流行的Web服务器,另外,我们还需要安装PHP软件以及如MySQL这样的数据库,具体内容可以查阅相关书籍或网站。下面我们讨论如何让PHP产生WML代码。
  
  在WWW中,PHP产生的第一行内容往往是: content-type: text/html
  
  但是,WAP终端是读不懂这样的标题的。WAP终端从服务器下载的单位是Deck,浏览的单位是Card,一般一个Deck就组成一个WML文件。那么,为WAP服务时,PHP文件中往往需要包含如下的代码:

  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";

  以上三行代码产生了WML文件(Deck)的文件头,这样WAP终端就可以识别所下载的Deck是否WML格式,并且接着显示余下的Deck内容。
  
  下面是一个最简单的Deck,它在WAP终端上显示"Hello World"。

 <?xml version="1.0" encoding="ISO-8859-1"?> <! DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "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>

  我们建立的相应的PHP文件如下:

  <?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>";
  ?>

  我们可以将该文件存为index.php3,当WAP终端浏览该网站时,Web服务器会自动根据index.php3的内容产生如上所列的WML内容,并发送给网关进行处理。WAP终端收到该Deck后,将会在显示屏上显示"Hello World"的字样。
  
  以上是关于PHP在WAP中最简单的应用,它只是简单地产生若干行WML代码,并没有牵扯到数据库的访问。其实,PHP强大的功能可以为WAP提供很丰富的服务,而最值得挖掘的就是其强大的数据库支持,这些将在以后的文章中讨论。



Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1655
14
PHP Tutorial
1253
29
C# Tutorial
1227
24
PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? Apr 03, 2025 am 12:03 AM

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

See all articles