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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

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)

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

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

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

In this chapter, we are going to learn the following topics related to routing ?

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

Validator can be created by adding the following two lines in the controller.

See all articles