search
HomeBackend DevelopmentPHP TutorialDetailed discussion of PHP WEB server related knowledge_PHP tutorial

We all know the power of PHP. Recently we have seen relevant knowledge about PHP WEB server. Let’s discuss this issue with you. WAP (Wireless Communication Protocol) is an open global standard for communication between digital mobile phones, personal handheld devices (PDA, etc.) and computers. Since static WAP pages cannot meet users' personalized service requests in many aspects, dynamic WML pages generated through WAP server-side language have wide application value and high commercial value.

The WAP application structure is very similar to the Internet. A typical WAP application request is like this: First, a mobile terminal with WAP user agent function (WAP mobile phone, etc. ) wirelessly sends a WAP service request to a certain website through the internally running Micro Browser. The request is first intercepted by the WAP gateway, which encodes and compresses the information content to reduce network data traffic. At the same time, the WAP protocol is converted into the HTTP protocol as needed, and then the processed request is forwarded to the corresponding WAP server. On the WAP server side, depending on the page extension and other properties, the requested page is output directly or is interpreted by a server-side script, and then transmitted back to the user through the gateway.

As can be seen from the above WAP application process, the process of generating dynamic WAP pages is very similar to the process of dynamically generating Web pages. However, since the WML language used by WAP applications is derived from XML with strict syntax, the output format must be output according to the specifications of the WAP web page. At the same time, due to the application scope of the WAP protocol and the software and hardware level of the mobile client, there are certain restrictions on the size of the page, image format and capacity each time it is output. Let's take the PHP script language as an example to see how to dynamically output a WAP page.

1. Set up PHP WEB server

First of all, your web server must have PHP installed, that is, it can handle PHP scripts. Secondly, in order for the PHP WEB server to recognize and process PHP, WML, WBMP and other files at the same time, the following file types need to be added to the MIME table of the Web server.

<ol class="dp-xml">
<li class="alt"><span><span>text/vnd.wap.wml .wml   </span></span></li>
<li class=""><span> </span></li>
<li class="alt"><span>image/vnd.wap.wbmp .wbmp   </span></li>
<li class=""><span> </span></li>
<li class="alt"><span>application/vnd.wap.wmlc .wmlc   </span></li>
<li class=""><span> </span></li>
<li class="alt"><span>text/vnd.wap.wmls.wmls  </span></li>
<li class=""><span> </span></li>
<li class="alt"><span>application/vnd.wap.wmlsc .wmlsc   </span></li>
</ol>

2. Use PHP to output a simple dynamic WAP page

The following is the simplest example of PHP generating a WAP page. Note that since a PHP interpreter is required to interpret this program and output the WAP page, all similar programs should have a .php extension.

<ol class="dp-xml">
<li class="alt"><span><strong><font color="#006699"><span class="tag"></span><span class="tag-name">php</span></font></strong><span> </span></span></li>
<li class=""><span>header(″Content-type: text/vnd.wap.wml″);  </span></li>
<li class="alt">
<span>echo (″</span><strong><font color="#006699"><span class="tag"><span class="tag-name">wml</span><span class="tag">></span></span></font></strong><span> </span><strong><font color="#006699"><span class="tag"><span class="tag-name">card</span><span class="tag">></span></span></font></strong><span> </span><strong><font color="#006699"><span class="tag"><span class="tag-name">p</span><span class="tag">></span></span></font></strong><span>″);  </span>
</li>
<li class=""><span>echo date( ″l dS of F Y h:i:s A″ );   </span></li>
<li class="alt">
<span>echo (″</span><strong><font color="#006699"><span class="tag"></span><span class="tag-name">p</span><span class="tag">></span><span class="tag"></span><span class="tag-name">card</span><span class="tag">></span><span class="tag"></span><span class="tag-name">wml</span><span class="tag">></span></font></strong><span>″);  </span>
</li>
<li class="">
<span></span><span class="tag"><strong><font color="#006699">?></font></strong></span><span> </span>
</li>
</ol>

This example can be browsed in the WAP mobile phone simulator and outputs the current date and time, but it cannot be recognized in ordinary browsers and may even be considered an error download. This is because the output document is declared as WML type at the beginning of the program, and this type can only be recognized and interpreted by the WAP device. It is worth noting that our common HTML language does not have strict normative requirements, and most browsers can "tolerate" quite a lot of writing errors, while WML specifications are quite strict, and a single mistake may result in the failure to output the required page.

Once we know the standard process of using PHP script to output WAP pages, we can use the powerful functions of PHP with the interactive processing of WML language and simple scripts of WML script to develop applications that suit our needs. System.

3. Use PHP to dynamically generate images

WAP applications use a special black and white image format WBMP. We can use some tools to convert existing images into WBMP format and then use them in WML documents. However, if the required images such as K-line charts can be dynamically generated on the WAP site, there will be broad application prospects. Fortunately, PHP's GD library (version 1.8 and above) already provides corresponding functions.

<ol class="dp-xml">
<li class="alt"><span><strong><font color="#006699"><span class="tag"></span><span class="tag-name">PHP</span></font></strong><span> </span></span></li>
<li class=""><span>Header(″Content-type: image/vnd.wap.wbmp″);  </span></li>
<li class="alt">
<span></span><span class="attribute"><font color="#ff0000">Sim</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">ImageCreate</font></span><span>(50, 50);  </span>
</li>
<li class="">
<span></span><span class="attribute"><font color="#ff0000">Swhite</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">ImageColorAllocate</font></span><span>(Sim,255,255,255);  </span>
</li>
<li class="alt">
<span></span><span class="attribute"><font color="#ff0000">Sblack</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">ImageColorAllocate</font></span><span>(Sim,0,0,0);  </span>
</li>
<li class=""><span>ImageRectangle(Sim, 5, 5, 20, 20, Sblack);  </span></li>
<li class="alt"><span>ImageWBMP(Sim); ImageDestroy(Sim);  </span></li>
<li class="">
<span></span><span class="tag"><strong><font color="#006699">?></font></strong></span><span> </span>
</li>
</ol>

The file will display a black rectangular box in the WAP emulator. Note that to use the GD image function library, the PHP_GD.DLL library file must be loaded in the PHP WEB server configuration.

4. Processing Chinese characters in PHP

WAP, as a global application, has chosen UNICODE 2.0 as its standard character set encoding so that it can simultaneously process English, Chinese, Japanese, French and other languages. We usually use GB2312 encoding to process Chinese characters. Different internal code standards are bound to be incompatible. Therefore, if the code table is not converted between the two encodings, garbled Chinese characters will appear. There are already relatively mature programs and functions for GB-2312 and UNICODE encoding conversion, and they are used in ASP, PHP, JSP and other systems. We can find them on some technology sites.

Most current WAP phones (Nokia7110, Ericsson R320S, etc.) use UTF-8 encoding, which is encoded by UNICODE. In this way, if we use Chinese characters (GB2312 encoding) directly in WML, garbled characters will be generated and mobile phone users cannot recognize them. Therefore, before we output Chinese, we must use a program or function to encode the Chinese with UNICODE. In a few mobile phones or WAP terminal devices that support GB2312 encoding, we can directly and correctly display Chinese characters after defining the internal code type of the document in the program, for example:

<ol class="dp-xml">
<li class="alt"><span><span class="tag"></span><span class="tag-name">php</span><span>   </span></span></li>
<li class="">
<span>header(″Content-type: text/vnd.wap.wml; </span><span class="attribute">charset</span><span>=</span><span class="attribute-value">gb2312</span><span>″);  </span>
</li>
<li class="alt">
<span>echo (″</span><span class="tag"><span class="tag-name">wml</span><span class="tag">></span><span class="tag"><span class="tag-name">card</span><span class="tag">></span><span class="tag"><span class="tag-name">p</span><span class="tag">></span><span>″);  </span></span><li class=""><span>echo (″中文测试″);  </span></li>
<li class="alt">
<span>echo (″</span><span class="tag"></span><span class="tag-name">p</span><span class="tag">></span><span class="tag"></span><span class="tag-name">card</span><span class="tag">></span><span class="tag"></span><span class="tag-name">wml</span><span class="tag">></span><span>″);  </span>
</li></span><li class="">
<span></span><span class="tag">?></span><span> </span>
</li></span>
</li>
</ol>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446475.htmlTechArticleWe all know the power of PHP. Recently we have seen relevant knowledge about PHP WEB server. Below we will Let’s discuss this issue with everyone. WAP (Wireless Communication Protocol) is...
Statement
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
What is the difference between the unset() and unlink() functions ?What is the difference between the unset() and unlink() functions ?Apr 30, 2025 pm 03:33 PM

The article discusses the differences between unset() and unlink() functions in programming, focusing on their purposes and use cases. Unset() removes variables from memory, while unlink() deletes files from the filesystem. Both are crucial for effec

What are Traits in PHP ?What are Traits in PHP ?Apr 30, 2025 pm 03:31 PM

PHP traits enable code reuse in single inheritance contexts, offering benefits like reusability and simplified inheritance. They can be effectively combined with traditional inheritance to enhance class flexibility and modularity.

Is PHP supports multiple inheritance ?Is PHP supports multiple inheritance ?Apr 30, 2025 pm 03:30 PM

PHP does not support multiple inheritance but uses interfaces and traits as alternatives to achieve similar functionality, avoiding issues like the diamond problem.

What is inheritance in PHP ?What is inheritance in PHP ?Apr 30, 2025 pm 03:29 PM

Inheritance in PHP allows classes to inherit properties and methods, promoting code reuse and hierarchical organization. Key benefits include reusability, abstraction, and polymorphism. Common mistakes to avoid are overuse of inheritance and ignoring

What are the main error types, and how do they differ?What are the main error types, and how do they differ?Apr 30, 2025 pm 03:28 PM

The article discusses three main error types in programming: syntax, runtime, and logical errors. It explains their causes, prevention strategies, impacts on performance and user experience, and methods for diagnosis and resolution.

How can PHP and HTML interact?How can PHP and HTML interact?Apr 30, 2025 pm 03:27 PM

Article discusses PHP and HTML interaction, best practices for embedding PHP in HTML, dynamic HTML content generation, and recommended development tools.

What is the difference between for and foreach loop in PHP?What is the difference between for and foreach loop in PHP?Apr 30, 2025 pm 03:26 PM

The article discusses the differences between for and foreach loops in PHP, focusing on syntax, usage, control, and performance. Foreach is preferred for array iteration due to simplicity and efficiency, but for loops are better for index-based opera

Explain the importance of Parser in PHP.for eachExplain the importance of Parser in PHP.for eachApr 30, 2025 pm 03:25 PM

The article discusses the crucial role of the PHP parser in script execution, focusing on its tasks in syntax analysis, error handling, and code optimization, and how its efficiency impacts web application performance.

See all articles

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

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor