A friend asked me how to use PHP and GD to output a picture of Chinese characters, I certainly call him first to search online, as a result, he said only to find a code table for conversion (GB2UNICODE?) Method, ask I have better, faster ways.
Of course, there is, and it's much more, it's too much, it is iconv, of course, this requires you to have administrators, after installing libiconv, compile PHP with -with-iconv parameter configuration Or generate a separate expansion module, all, after, you can use the ICONV function to be converted directly. Like this below:
PHP
Header ("Content-Type: Image / GIF");
$ PIC = ImageCreate (500, 400);
$ black = imagecolorallocate ($ PIC, 150, 150, 150);
$ color = imagecoloralloccate ($ PIC, 5, 5, 5);
$ font1 = "/ home / share / font / simli.ttf";
$ font2 = "/ home / share / font / simhei.ttf";
$ font3 = "/ home / share / font / simsun.ttf";
$ font4 = "/ home / share / font / simyou.ttf";
$ STR1 = ICONV ("GB2312", "UTF-8", "Leave the original grass, one year old and a moon.");
$ STR2 = ICONV ("GB2312", "UTF-8", "wildfire is not enough, spring breeze is born again.");
$ STR3 = ICONV ("GB2312", "UTF-8", "Yuanfang invaded the ancient road, Qingcui Jingcheng.");
$ STR4 = ICONV ("GB2312", "UTF-8", "Send Wang Sun to go, full of love.");
// ImagetTfText ($ PIC, 16, 0, 155, 365, $ Color, $ FONT1, $ STR1);
// iMagetTfText ($ PIC, 16, 0, 155, 405, $ Color, $ font2, $ str2;
// iMagetTfText ($ PIC, 16, 10, 155, 445, $ Color, $ font3, $ str3;
// iMagetTfText ($ PIC, 16, 0, 155, 485, $ Color, $ FONT4, $ STR4;
ImageGIF ($ PIC);
ImageDestroy ($ PIC);
?>
The main effective statement is $ STR = ICONV ("GB2312", "UTF-8", "Chinese string");
Take a look, more simple! Of course, when there is no Libiconv and PHP extension, the conversion code table is the only choice. Write here, give you more than one reference.
In addition, I use Libiconv is 1.7 version, from GB2312 to UTF-8, it is normal, but BIG5 is not normal, of course, I don't have to traditional, this is not much deal.