Home >Backend Development >PHP Tutorial >PHP generates dynamic WAP page 3_PHP tutorial
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.
$#@60;?PHP
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) ;
?$#@62;
The file will display a black rectangle in the WAP emulator. Note that to use GD's image function library, the PHP_GD.DLL library file must be loaded in the PHP configuration.
IV. Processing Chinese characters in PHP
As a global application, WAP has chosen UNICODE 2.0 as its standard character set encoding so that it can process multiple texts including English, Chinese, Japanese, French, etc. at the same time. 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 of the current WAP mobile 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 small number of 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: