Php coding and conversion implementation code (16 ). We provide several types of encoding conversion, such as UTF-8 to GB encoding GB to UTF-8 encoding Unicode to utf8unicodeurl encoding to gbk encoding function GB code to convert Big5 code Big5 code to GB code utf8 to Unico we provides several types of encoding conversion, such as UTF-8 to GB encoding GB to UTF-8 encoding Unicode to utf8 unicode url encoding to gbk encoding function GB code conversion to Big5 code Big5 code to GB code utf8 to Unicode wait.
We provide several types of encoding conversion, such as UTF-8 to gb encoding gb to UTF-8 encoding unicode to utf8 unicode url encoding to gbk encoding function gb to convert big5 to big5 to UTF-8 unicode.
*/
$ Uc2gbtable = $ codetable = $ big5_data = $ gb_data = '';
$ Gbkunidic = null;
// UTF-8 to gb encoding
Function utf82gb ($ utfstr)
{
If (function_exists ('iconv '))
{
Return iconv ('utf-8', 'gbk // ignore ', $ utfstr );
}
Global $ uc2gbtable;
$ Okstr = "";
If (trim ($ utfstr) = "")
{
Return $ utfstr;
}
If (empty ($ uc2gbtable ))
{
$ Filename = dedeinc. "/data/gb2312-utf8.dat ";
$ Fp = fopen ($ filename, "r ");
While ($ l = fgets ($ fp, 15 ))
{
$ Uc2gbtable [hexdec (substr ($ l, 7, 6)] = hexdec (substr ($ l, 0, 6 ));
}
Fclose ($ fp );
}
$ Okstr = "";
$ Ulen = strlen ($ utfstr );
For ($ I = 0; $ I <$ ulen; $ I ++)
{
$ C = $ utfstr [$ I];
$ Cb = decbin (ord ($ utfstr [$ I]);
If (strlen ($ cb) = 8)
{
$ Csize = strpos (decbin (ord ($ cb), "0 ");
For ($ j = 0; $ j <$ csize; $ j ++)
{
$ I ++; $ c. = $ utfstr [$ I];
}
$ C = utf82u ($ c );
If (isset ($ uc2gbtable [$ c])
{
$ C = dechex ($ uc2gbtable [$ c] + 0x8080 );
$ Okstr. = chr (hexdec ($ c [0]. $ c [1]). chr (hexdec ($ c [2]. $ c [3]);
}
Else
{
$ Okstr. = "& #". $ c .";";
}
}
Else
{
$ Okstr. = $ c;
}
}
$ Okstr = trim ($ okstr );
Return $ okstr;
}
1 2 3 4 5 6
Refer to GB encoding GB to UTF-8 encoding Unicode to utf8 unicode url encoding to gbk encoding function GB code to convert Big5 code Big5 code to GB code utf8 to Unico...