1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | <?php //======================================================================= // File: JPGRAPH_GB2312.PHP // Description: Chinese font conversions // Created: 2003-05-30 // Ver: $Id: jpgraph_gb2312.php 1106 2009-02-22 20:16:35Z ljp $ // // Copyright (c) Aditus Consulting. All rights reserved. //======================================================================== class GB2312toUTF8 { // -------------------------------------------------------------------- // This code table is used to translate GB2312 code (key) to // it's corresponding Unicode value (data) // -------------------------------------------------------------------- ''; while($gb) { if( ord(substr($gb,0,1)) > 127 ) { $t=substr($gb,0,2); $gb=substr($gb,2); $utf8 .= $this->u2utf8($this->codetable[hexdec(bin2hex($t))-0x8080]); } else { $t=substr($gb,0,1); $gb=substr($gb,1); $utf8 .= $this->u2utf8($t); } } return $utf8; } function u2utf8($c) { $str=''; if ($c < 0x80) { $str.=$c; } else if ($c < 0x800) { $str.=chr(0xC0 | $c>>6); $str.=chr(0x80 | $c & 0x3F); } else if ($c < 0x10000) { $str.=chr(0xE0 | $c>>12); $str.=chr(0x80 | $c>>6 & 0x3F); $str.=chr(0x80 | $c & 0x3F); } else if ($c < 0x200000) { $str.=chr(0xF0 | $c>>18); $str.=chr(0x80 | $c>>12 & 0x3F); $str.=chr(0x80 | $c>>6 & 0x3F); $str.=chr(0x80 | $c & 0x3F); } return $str; } } // END Class ?> |