For example, put: "The latest recommendation GB" is converted to:
Latest recommendation GB
Excuse me. Thank you
-------------------------------------------------- -------------
Test success, gb2312.txt download
http://www.phpx.com/download/utf8/gb2312.txt
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, 0, 6))] = Substr ($ Value, 7, 6);
$ UTF8 = ""
While ($ GB)
{
IF (ORD (Substr ($ GB, 0, 1)> 127)
{
$ this = Substr ($ GB, 0, 2);
$ GB = SUBSTR ($ GB, 2, STRLEN ($ GB));
$ UTF8. = "& # x" .Dechex (HEXDEC ($ CODETABLE [HEXDEC (Bin2Hex ($ this)) - 0x8080])). ";";
}
Else
{
$ UTF8. = "& # x" .Dechex (ORD (Substr ($ GB, 0, 1))))). ";";
$ GB = SUBSTR ($ GB, 1, STRLEN ($ GB));
}
}
RETURN $ UTF8;
}
ECHO GB2UTF8 ("Chinese ABC");