WAP(无线通讯协议)是在数字移动电话、个人手持设备(PDA等)及计算机之间进行通讯的开放性全球标准。由于静态的WAP页面在很多方面不能满足用户个性化的服务请求,因此通过WAP服务器端语言产生动态的WML页面,具有很广泛的应用价值和很高的商业价值。 ″); ″);
WAP应用结构非常类似于Internet,一个典型的WAP应用请求是这样的:首先,具有WAP用户代理功能的移动终端(WAP手机等)通过内部运行的微浏览器(Micro Browser)对某一网站以无线方式发送WAP服务请求。该请求先由WAP网关截获,对信息内容进行编码压缩,以减少网络数据流量,同时根据需要将WAP协议转换成HTTP协议,然后将处理后的请求转送到相应WAP服务器。在WAP服务器端,根据页面扩展名等性质,被请求的页面直接或由服务器端脚本解释后输出,再经网关传回用户。
从上述WAP应用流程可以看到,生成动态WAP页面与动态产生Web网页的过程非常类似。但是由于WAP应用使用的WML语言来源于语法严格的XML,因此要求输出的格式必须按WAP网页的规范输出。同时,由于WAP协议的应用范围、移动客户端的软硬件水平等特殊性,对每次输出的页面的大小、图像的格式及容量都有一定限制。下面我们以PHP脚本语言为例,看看如何动态输出WAP页面。
一、设置WEB服务器
首先你的 Web服务器要安装好PHP,即能处理PHP脚本程序。其次,为使Web服务器能同时识别和处理PHP、WML、WBMP等文件,Web 服务器的MIME表需添加以下的几种文件类型。
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
二、用PHP输出简单动态WAP页面
下面有一个最简单的PHP生成WAP页面的例子。注意由于需要PHP解释器来解释该程序,并输出WAP页面,因此所有类似程序应以.php为扩展名。
header(″Content-type: text/vnd.wap.wml″);
echo (″
echo date( ″l dS of F Y h:i:s A″ );
echo (″
?>
该例子在WAP手机模拟器中可以浏览,输出当前日期时间,而在普通的浏览器中无法识别,甚至会被认为是错误下载。这是因为在程序开头就声明了该输出文档为WML类型,该类型只有WAP设备能够识别并解释。值得注意的是,我们常见的HTML语言对规范性要求不严,大多数浏览器能“容忍”其中相当多的编写错误,而WML规范相当严格,一点失误都可能导致无法输出所需页面。
一旦我们知道了用PHP脚本输出WAP页面的标准过程,我们就能够使用PHP强大的功能配合以WML语言的交互处理以及WML Script的简单脚本,开发出适合我们需要的应用系统了。
三、用PHP动态生成图像
WAP应用使用一种特殊黑白的图像格式WBMP。我们可以用一些工具来将已有图像转换成WBMP格式,然后在WML文档中使用。但是在WAP站点上如果能动态地生成所需图像如K线图等,将会有广阔的应用前景。幸运的是,PHP的GD库(版本1.8以上)已经提供了相应函数。
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, 20, 20, Sblack);
ImageWBMP(Sim); ImageDestroy(Sim);
?>
该文件将在WAP模拟器中显示一个黑色矩形框。注意要使用GD的图像函数库,必须在PHP配置中加载PHP_GD.DLL库文件。
四、在PHP中处理汉字
WAP作为一种全球应用,选择了UNICODE 2.0作为其标准字符集编码,以便能同时处理包括英文、中文、日文、法文等多种文字。而我们平常处理汉字使用的是GB2312编码,不同的内码标准势必不能通用,因此如果不在两种编码之间通过码表进行转换,就会出现汉字乱码现象。现在已经有较成熟的GB-2312与UNICODE编码转换的程序和函数,并在ASP、PHP、JSP等系统中使用,我们可以在一些技术站点上找到它们。
目前的大多数WAP手机(Nokia7110、爱立信R320S等等)都是使用UTF-8编码的,也就是采用UNICODE来编码。这样,如果我们直接在WML使用中文字符(GB2312编码),将会产生乱码,手机用户无法识别,所以我们在输出中文之前,要使用程序或函数对中文进行UNICODE的编码。而在少数支持GB2312编码的手机或WAP终端设备中,我们可以在程序中定义好文档的内码类型后即可直接正确显示汉字,例如:
header(″Content-type: text/vnd.wap.wml; charset=gb2312″);
echo (″
echo (″中文测试″);
echo (″
?>

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python are both high-level programming languages that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

SublimeText3 Linux new version
SublimeText3 Linux latest version

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SublimeText3 English version
Recommended: Win version, supports code prompts!

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.