Ã÷»ÔÕ¾/ÍøÕ¾½Ì³Ì/ÄÚÈÝ

ÈçºÎ½«gbk±àÂëת»»utf8¸ñʽ

ÍøÕ¾½Ì³Ì2024-02-15 ÔĶÁ
[ÕªÒª]apache ×Ö·û¼¯ GB 2312mysql ×Ö·û¼¯ GBKÏÖÒª´Ó mysql ÖÐÌá³öÐÅÏ¢(GBK) дÈëµ½ XML ÖÐXMLÖеıàÂë¸ñʽÊÇ UTF-8ÄÇô£¬ÈçºÎ½«GBK±àÂë³É UTF8 £¿£¿Ïêϸ½éÉÜ:Ç°Ò»Õó×Ó¼ûµ½ÁËqiushuiwuhen¾ýµÄ¹ØÓÚgbk,unicode,big5µÄת»»µÄÎÄÕ µ«...
apache ×Ö·û¼¯ GB 2312
mysql ×Ö·û¼¯ GBK
ÏÖÒª´Ó mysql ÖÐÌá³öÐÅÏ¢(GBK) дÈëµ½ XML ÖÐ
XMLÖеıàÂë¸ñʽÊÇ UTF-8

ÄÇô£¬ÈçºÎ½«GBK±àÂë³É UTF8 £¿£¿

Ïêϸ½éÉÜ:
Ç°Ò»Õó×Ó¼ûµ½ÁËqiushuiwuhen¾ýµÄ¹ØÓÚgbk,unicode,big5µÄת»»µÄÎÄÕÂ
µ«ÊǶàÉÙÓÐһЩ²»Ì«´óµÄÎÊÌâ

ÓÚÊÇÎÒÉè¼ÆÁËÒ»¸ö¸ºÔð×Ö·ûת»»µÄÀà,ÐÞÕýÁËÆäÖеÄһЩ²»×㣬Ôö¼ÓÁ˲¿·Ö¹¦ÄÜ,ÒÔºóÎһ᲻¶ÏÀ©³ä¸ÃÀ࣬À´Ö§³Ö¸ü¶àµÄ×Ö·û¼¯

Ôö¼ÓÁËÈçϼ¸µã£º

unicode->gbk ·ûºÅ²¿·ÖµÄת»»
Å·Ôª·û(€µÄʶ±ð
big5,Unicode,GBKÖ®¼äµÄÏ໥ת»»,Ç°ÌáÊÇֻת»»¹²Í¬µÄ×Ö·û¼¯²¿·Ö,

ʹÓÃ˵Ã÷:
ÔÝʱ³ÌÐòÖ§³ÖÒÔÏÂ×Ö·û±àÂ뷽ʽ:
GBK,BIG5,UTF-16BE(Unicode big-endian×Ö½Ú˳Ðò),UTF-16LE(Unicode little-endian×Ö½Ú˳Ðò),UTF-8
ĬÈÏÊäÈë±àÂ뷽ʽΪGBK,ĬÈÏÊä³ö±àÂ뷽ʽΪUTF-16BE;
¸ÃÀà±ðÌṩÁ½¸öº¯ÊýÓÃÀ´ÐÞ¸ÄÊäÈëºÍÊä³ö±àÂ뷽ʽ£º
ÐÞ¸ÄÊäÈë±àÂ뷽ʽ boolean SetGetEncoding(string $GetEncoding)
ÐÞ¸ÄÊä³ö±àÂ뷽ʽ boolean SetToEncoding(string $ToEncoding)
º¯Êý²ÎÊýÖ»ÄÜʹÓÃÉÏÊö5ÖÖ±àÂ뷽ʽ£¬Çø·Ö´óСд,ÈçGBK²»ÄÜд³Égbk
Èç¹ûÉèÖóɹ¦,·µ»Øtrue,Èç¹ûʹÓÃÁË´íÎóµÄ±àÂëÃû,·µ»Øfalse,²¢ÏÖʵ´íÎóÐÅÏ¢

º¯Êý
string EncodeString(string $String)
¸ºÔð½øÐÐ×Ö·û±àÂëת»»,·µ»Øת»»ºóµÄ×Ö·û´®

ʹÓÃÇ°,Ç뽫var $FilePath=\"\"±äÁ¿¸ÃΪ¸Ã³ÌÐòÎļþµÄ¾ø¶Ô·¾¶,·ñÔò½«»áÕÒ²»µ½Êý¾ÝÎļþ

Àý×Ó£º
½«gbk±àÂëµÄ×Ö·û´®×ª»¯ÎªUTF-8±àÂë:

$s=\"GBK±àÂë\";
$CharEncoding=new Encoding();
$CharEncoding->SetGetEncoding(\"GBK\") die(\"±àÂëÃû´íÎó\");
$CharEncoding->SetToEncoding(\"UTF-8\") die(\"±àÂëÃû´íÎó\");
echo $CharEncoding->EncodeString($s);

ÔÚä¯ÀÀÆ÷ÖÐʹÓÃUTF-8±àÂë²ì¿´,½«»á¿´µ½ÕýÈ·µÄ×Ö·û.

¸½¼þ: encoding.zip

……

Ïà¹ØÔĶÁ