Home > Backend Development > PHP Tutorial > GD Chinese character display principle_PHP tutorial

GD Chinese character display principle_PHP tutorial

WBOY
Release: 2016-07-13 17:25:07
Original
1480 people have browsed it

Let me tell you here about the principle of displaying Chinese in GD. I believe you can write one down after reading it.
The GD library in PHP actually supports Chinese, but it must be passed in UTF-8 format parameters. You can try the following applet.
You will be able to see a graphic with the words "Chinese OK" displayed. (
UTF-8: Unicode Transfer Format 8 is a compatible representation of Unicode)
Header("Content-type: image/gif") ;
$im = imagecreate(400,300);
$bkg = ImageColorAllocate($im, 0,0,0);
$clr = ImageColorAllocate($im, 255,255,255);
$fnt = "c:/winnt/fonts/simhei.ttf";
// if 98/95 "c:/windows/fonts/simhei.ttf";
$str = chr(0xE4).chr(0xB8) .chr(0xAD).chr(0xE6).chr(0x96).chr(0x87)."OK";
// "Chinese OK" in UTF-8ImageTTFText($im, 20, 0, 10, 20, $clr, $fnt, $str);
ImageGif($im);
ImageDestroy($im);?> 
If you just want to display a fixed Chinese string, you can use Word, Four Use Tongcube and other software to convert the characters to be displayed into UTF-8 format, and then paste them into the program. If you want to dynamically display corresponding Chinese characters based on user input, then you must solve the problem of converting the internal code of Chinese characters into UTF-8 format.
I am not very clear about Chinese processing under UNIX/Linux and have no say. If it uses Unicode internal code, Unicode should be converted into UTF-8 format.
If GBK internal code is used like Win95/98, it should be converted to Unicode first and then to UTF-8 format.


Regarding the conversion of GBK-Unicode, I used a very stupid solution, and I propose it here for everyone to discuss. I hope everyone can come up with a simpler and more efficient solution.
I first use this small program to display all GBK characters, and then convert them to Unicode in Word. Convert each character into the corresponding Unicode value according to this string. The process of representing Unicode to UTF-8 refers to the conversion programs cvtutf.c, cvtutf.h on Unicode.
for($i = 0x81; for($i = 0x81;
$i // 0x81 - 0xFE
for($j = 0x40; $j // 0x40 - 0x7E 0x80 - 0xFE
if($j != 0x7F){
echo chr($i).chr($j);
} } }?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/532075.htmlTechArticleLet me tell you about the principle of displaying Chinese in GD. I believe you can write one down after reading it. The GD library in PHP actually supports Chinese, but it must be in UTF-8 format...
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template