P> conversion of UTF8 Chinese characters using GBK Unicode
Converting Chinese Characters in php has always been a problem.
This class has four built-in filters "& # [dec];", "& # x [hex];", "% u [hex]", "utf8 conversion"
It is convenient for users and supports custom Filtering for their favorite operations.
QswhU. php download from here
Http://www.blueidea.com/user/qswh/qswhU.zip
Class qswhU {
Var $ qswhData;
Function qswhU ($ filename = "qswhU. php "){
$ This-> qswhData = file ($ filename );
}
Function decode ($ str, $ pattern = 0 ){
$ Arr = array ("/& # (w +);/iU", "/(% ww) +)/I ", "/% u (w {4, 5})/iU ");
If (is_integer ($ pattern )){
If ($ pattern> = count ($ arr) die ("Invalid Function ");
$ Pattern = $ arr [$ pattern];
}
Return preg_replace_callback ($ pattern, array ($ this, "u2gb"), $ str );
}
Function u2gb ($ arr ){
/***** (Qiushuiwuhen 2002-8-15 )******/
$ Ret = ""; $ str = $ arr [1];
If (preg_match_all ("/% w {2}/", $ str, $ matches )){
For ($ I = 0; $ I <count ($ matches [0]); $ I ++ ){
$ Chr1 = hexdec (substr ($ matches [0] [$ I], 1 ));
$ Arr = array ("f0", "e0", "c0", "0 ");
For ($ j = 0; $ j <count ($ arr); $ j ++) if ($ chr1> hexdec ($ arr [$ j]) break;
$ Chr = hexdec (substr ($ matches [0] [$ I], 1)-hexdec ($ arr [$ j]);
While (++ $ j <count ($ arr) $ chr = $ chr * 0x40 + (hexdec (substr ($ matches [0] [++ $ I], 1)-0x80 );
$ Str = dechex ($ chr );
If (strlen ($ str) = 4 ){
$ P = hexdec (substr ($ str, 0, 2)-0x4d;
$ Q = hexdec (substr ($ str, 2) * 4;