Class GB2UTF8 V2.0.1

zhaozj2021-02-16  83

http://www.chinaunix.net Author: HonestQiao Posted: 2003-08-01 18:27:21

GB2UTF8.php files are as follows:

[CODE: 1: FD411E9991D]

Function GB2UTF8 ($ INSTR = ") {$ this-> GB = $ INSTR; $ this-> setgb2312 (); ($ this-> gb ==" ")? 0: $ this-> convert ();}

Function setgb2312 ($ INSTR = "gb2312.txt") {// set the GB2312 code file, default is GB2312.txt $ this-> errormsg = ""; $ TMP = @ file ($ INSTR); if (! $ tmp) {$ This-> error = "no gb2312"; return false;} $ this-> codetable = array (); while ($ key, $ value) = Each ($ THIS-> CODETABLE [ HEXDEC (Substr ($ Value, 0, 6))] = Substr ($ Value, 7, 6);}} Function Convert () {// Convert GB2312 string to UTF8 string, need to pre-set $ GB $ THIS- > utf8 = ""; if (! trim ($ this-> GB) || $ this-> errormsg! = "") {return ($ this-> utf8 = $ this-> errormsg);} $ strromsg);} $ str = $ THIS-> GB;

While ($ Str) {if (Substr ($ Str, 0, 1))> 127) {$ TMP = Substr ($ Str, 0, 2); $ Str = Substr ($ Str, 2, Strlen ($ SUBSTR ($ Str, 2, Strlen) Str); $ TMP = $ THIS-> U2UTF8 ($ this-> CodeTable [HEXDEC (bin2hex ($ TMP)) - 0x8080]); for ($ I = 0; $ I utf8. = CHR (Substr ($ TMP, $ I, 3));} else {$ TMP = Substr ($ Str, 0, 1); $ Str = Substr ($ Str , 1, Strlen ($ STR)); $ this-> utf8. = $ Tmp;}} Return $ this-> utf8;}

Function U2UTF8 ($ INSTR) {for ($ I = 0; $ I > 6); $ Str. = (0x80 | $ INSTR & 0X3F); Else IF ($ INSTR <0x10000) {$ STR. = (0xE0 | $ INSTR >> 12); $ Str. = (0x80 | $ INSTR >> 6 & 0x3F); $ Str. = (0x80 | $ INSTR & 0X3F);} else IF ($ INSTR <0x200000) { $ Str. = (0xf0 | $ INSTR >> 18); $ Str. = (0x80 | $ INSTR >> 12 & 0x3F); $ Str. = (0x80 | $ INSTR >> 6 & 0x3F); $ Str. = (0x80 | $ INSTR & 0X3F);} RETURN $ STR;}}?> [/ Code: 1: FD411E991D] Test files are as follows: [CODE: 1: fd411e991d] gb = "123ABC China 456DEF test correct"; $ obj-> convert (); imagettftext ($ IM, 20, 0, 5, 50, $ White, "Simkai.ttf ", $ obj-> utf8; imagepng ($ IM); ImageDestroy;?> [/ code: 1: fd411e991d]

Description: You need to set up a font file correctly. Please confirm that you can use Font to export English directly (without using GB2UTF8). GB2312.TXT Please look online

转载请注明原文地址:https://www.9cbs.com/read-14886.html

New Post(0)