Thanks to sadly for writing the function for outputting Chinese characters in GD, I found that the strings output in this version must be pure Chinese and cannot be mixed with English. with this bug modified, share with you.
Thanks to sadly for writing the function for outputting Chinese characters in GD, I found that the strings output in this version must be pure Chinese and cannot be mixed with English. with this bug modified, share with you.
-
- // Program writen by sadly www.phpfensi.com
- // Modified by agun 2013/6/20
- Function gb2utf8 ($ gb)
- {
- If (! Trim ($ gb ))
- Return $ gb;
- $ Filename = "gb2312.txt ";
- $ Tmp = file ($ filename );
- $ Codetable = array ();
- While (list ($ key, $ value) = each ($ tmp ))
- $ Codetable [hexdec (substr ($ value,)] = substr ($ value );
- $ Ret = "";
- $ Utf8 = "";
- While ($ gb)
- {
- If (ord (substr ($ gb, 127)>)
- {
- $ This = substr ($ gb, 0, 2 );
- $ Gb = substr ($ gb, 2, strlen ($ gb ));
- $ Utf8 = u2utf8 (hexdec ($ codetable [hexdec (bin2hex ($ this)-0x8080]);
- For ($ I = 0; $ I
- $ Ret. = chr (substr ($ utf8, $ I, 3 ));
- }
- Else
- {
- $ Ret. = substr ($ gb, 0, 1 );
- $ Gb = substr ($ gb, 1, strlen ($ gb ));
- }
- }
- Return $ ret;
- }
- Function u2utf8 ($ c)
- {
- For ($ I = 0; $ I
- $ Str = "";
- If ($ c <0x80 ){
- $ Str. = $ c;
- }
- Else if ($ c <0x800 ){
- $ Str. = (0xC0 | $ c> 6 );
- $ Str. = (0x80 | $ c & 0x3F );
- }
- Else if ($ c <0x10000 ){
- $ Str. = (0xE0 | $ c> 12 );
- $ Str. = (0x80 | $ c> 6 & 0x3F );
- $ Str. = (0x80 | $ c & 0x3F );
- }
- Else if ($ c <0x200000 ){
- $ Str. = (0xF0 | $ c> 18 );
- $ Str. = (0x80 | $ c> 12 & 0x3F );
- $ Str. = (0x80 | $ c> 6 & 0x3F );
- $ Str. = (0x80 | $ c & 0x3F );
- }
- Return $ str;
- }
- Header ("Content-type: image/gif ");
- $ Im = imagecreate (300,150 );
- $ Bkg = ImageColorAllocate ($ im, 0, 0 );
- $ Clr = ImageColorAllocate ($ im, 255,255,255 );
- $ Fnt = "c: windowsfontssimsun. ttf ";
- // Include ("gb2utf8. php ");
- $ Str = gb2utf8 ("China agun sticks ");
- ImageTTFText ($ im, 30, 0, 50, 50, $ clr, $ fnt, $ str );
- ImageGif ($ im );
- ImageDestroy ($ im );
- ?>