PHP³ÌÐoÉe¼ÆÖÐÖÐÎıaÂeÎÊÌaÔø¾À§ÈźܶaÈË£¬µ¼ÖÂÕa¸oÎÊÌaµÄÔÒoÆaʵºÜ¼oµ¥£¬Ã¿¸o¹u¼Ò(»oÇøÓo)¶¼¹ae¶¨Á˼ÆËa»uÐÅÏ¢½»»»ÓõÄ×Öu±aÂe¼¯£¬ÈçÃÀ¹uµÄÀ(C)Õ¹ ASCII Âe, ÖйuµÄ GB2312-80£¬ÈÕ±¾µÄ JIS µÈ¡£×÷Ϊ¸Ã¹u¼Ò/ÇøÓoÄÚÐÅÏ¢´¦ÀiµÄ»u´¡£¬×Öu±aÂe¼¯Æð×Åͳһ±aÂeµÄÖØÒª×÷Óá£×Öu±aÂe¼¯°´³¤¶ÈÖΪ SBCS(µ¥×Ö½Ú×Öu¼¯)£¬DBCS(Ë«×Ö½Ú×Öu¼¯)Á½´oÀa¡£ÔçÆÚµÄÈi¼þ(ÓÈÆaÊDzÙ×÷ϵͳ)£¬ÎªÁ˽a¾o±¾µØ×ÖuÐÅÏ¢µÄ¼ÆËa»u´¦Ài£¬³oÏÖÁ˸÷ÖÖ±¾µØ»¯°ae±¾(L10N)£¬ÎªÁËÇøÖ£¬Òý½øÁË LANG, Codepage µÈ¸ÅÄi¡£µ«ÊÇÓÉÓÚ¸÷¸o±¾µØ×Öu¼¯´uÂe¶Î§Öصþ£¬Ïa»¥¼aÐÅÏ¢½»»»À§ÄÑ;Èi¼þ¸÷¸o±¾µØ»¯°ae±¾¶ÀÁ¢Î¬»¤³É±¾½Ï¸ß¡£Òo´ËÓбØÒª½«±¾µØ»¯¹¤×÷ÖеĹ²ÐÔ³eÈ¡³oÀ´£¬×÷Ò»Ö´¦Ài£¬½«ÌرðµÄ±¾µØ»¯´¦ÀiÄÚÈݽµµÍµ½×iÉÙ¡£ÕaÒ²¾ÍÊÇËuνµÄ¹u¼Ê»¯(118N)¡£¸÷ÖÖÓiÑÔÐÅÏ¢±»½øÒ»²½¹ae¶Îª Locale ÐÅÏ¢¡£´¦ÀiµÄµ×²a×Öu¼¯±a³ÉÁ˼¸ºo°uº¬ÁËËuÓÐ×ÖÐ뵀 Unicode¡£
ÏÖÔÚ´o²¿Ö¾ßÓйu¼Ê»¯ÌØÕ÷µÄÈi¼þºËÐÄ×Öu´¦Ài¶¼ÊÇÒÔ Unicode Ϊ»u´¡µÄ£¬ÔÚÈi¼þÔËÐÐʱ¸u¾Ýµ±Ê±µÄocale/Lang/Codepage ÉeÖÃȶ¨ÏaÓ¦µÄ±¾µØ×Öu±aÂeÉeÖ㬲¢ÒÀ´Ë´¦Ài±¾µØ×Öu¡£ÔÚ´¦Ài¹ý³ÌÖÐÐeҪʵÏÖ Unicode ºÍ±¾µØ×Öu¼¯µÄÏa»¥×ª»»£¬Éo»oÒÔ Unicode ΪÖмaµÄÁ½¸o²»Í¬±¾µØ×Öu¼¯µÄÏa»¥×ª»»¡£ÕaÖֽʽÔÚÍøÂ绾³Ï±»½øÒ»²½ÑÓÉi£¬ÈκÎÍøÂçÁ½¶ËµÄ×ÖuÐÅÏ¢Ò²ÐeÒª¸u¾Ý×Ö*u¼¯µÄÉeÖÃת»»³É¿É½ÓÊܵÄÄÚÈÝ¡£
*Êý¾Ý¿aÖеÄ×Öu¼¯±aÂeÎÊÌa
*Á÷ÐеĹØϵÊý¾Ý¿aϵͳ¶¼Ö§³ÖÊý¾Ý¿a×Öu¼¯±aÂe£¬Ò²¾ÍÊÇ˵ÔÚ´´½¨Êý¾Ý¿aʱ¿ÉÒÔÖ¸¶¨Ëu×Ô¼ºµÄ×Öu¼¯ÉeÖã¬Êý¾Ý¿aµÄÊý¾ÝÒÔÖ¸¶¨µÄ±aÂeÐÎʽ´ae´¢¡£µ±Ó¦ÓóÌÐoÃÎÊÊý¾Ýʱ£¬ÔÚÈe¿ÚºÍ³o¿Ú´¦¶¼»aÓÐ×Öu¼¯±aÂeµÄת»»¡£¶ÔÓÚÖÐÎÄÊý¾Ý£¬Êý¾Ý¿a×Öu±aÂeµÄÉeÖÃÓ¦µ±±£Ö¤Êý¾ÝµÄÍeÕuÐÔ¡£GB2312¡¢GBK¡¢UTF-8 µÈ¶¼ÊÇ¿ÉÑ¡µÄÊý¾Ý¿a×Ö*u¼¯±aÂe;µ±È»ÎÒÃÇÒ²¿ÉÒÔÑ¡Ôñ ISO8859-1 (8-bit)£¬Ö»ÊÇÎÒÃǵÃÔÚÓ¦
ÓóÌÐoдÊý¾Ý֮ǰÏȽ« 16Bit µÄÒ»¸oºº×Ö»o Unicode ²ðÖ³ÉÁ½¸o 8-bit µÄ×Öu£¬¶ÁÊý¾ÝÖ®ºoÒ²ÐeÒª½«Á½¸o×ֽںϲ¢ÆðÀ´£¬Í¬Ê±»¹ÒªÅбðÆaÖÐµÄ SBCS ×Öu£¬Òo´ËÎÒÃDz¢²»ÍƼo²ÉÓà ISO8859-1 ×÷ΪÊý¾Ý¿a×Öu¼¯±aÂe¡£ÕaÑu²»µ«Ã»ÓгaÖÀuÓÃÊý¾Ý¿a×ÔÉiµÄ×Öu¼¯±aÂeÖ§³Ö£¬¶øÇÒͬʱҲÔo¼ÓÁ˱a³ÌµÄ¸´ÔӶȡ£±a³Ìʱ£¬¿ÉÒÔÏÈÓÃÊý¾Ý¿a¹ÜÀiϵͳÌa¹(C)µÄ¹ÜÀi¹¦Äܼi²eÆaÖеÄÖÐÎÄÊý¾ÝÊÇñÕýÈ¡£
PHP ³ÌÐoÔÚ²eѯÊý¾Ý¿a֮ǰ£¬Ê×ÏÈÖ´ÐÐ mysql_query("SET NAMES xxxx"); ÆaÖÐ xxxx ÊÇÄaÍøÒ³µÄ±aÂe(charset=xxxx)£¬Èç¹uÍøÒ³ÖÐ charset=utf8£¬Ôo xxxx=utf8£¬Èç¹uÍøÒ³ÖÐ charset=gb2312£¬Ôoxxxx=gb2312£¬¼¸ºoËuÓÐ WEB ³ÌÐo£¬¶¼ÓÐÒ»¶ÎÁ¬½ÓÊý¾Ý¿aµÄ¹«¹²´uÂe£¬*ÅÔÚÒ»¸oÎļþÀi£¬ÔÚÕaÎļþÀi£¬¼ÓÈe mysql_query("SET NAMES xxxx") ¾Í¿ÉÒÔÁË¡£
SET NAMES ÏÔʾ¿Í»§¶Ë¢Ë굀 SQL Ói¾aÖÐʹÓÃʲô×Öu¼¯¡£Òo´Ë£¬SET NAMES 'utf-8' Ói¾a¸aeËßþÎñÆ÷¡°½«À´´ÓÕa¸o¿Í»§¶Ë´«À´µÄÐÅÏ¢²ÉÓÃ×Öu¼¯ utf-8¡±¡£Ëu»¹ÎªþÎñÆ÷¢Ëͻؿͻ§¶ËµÄ½a¹uÖ¸¶¨ÁË×Öu¼¯(ÀýÈ磬Èç¹uÄaʹÓÃÒ»¸o SELECT Ói¾a£¬Ëu±iʾÁÐֵʹÓÃÁËʲô×Öu¼¯)¡£
¶¨Î»ÎÊÌaʱ³£Óõļ¼ÇÉ
¶¨Î»ÖÐÎıaÂeÎÊÌaͨ³£²ÉÓÃ×i±¿µÄÒ²ÊÇ×iÓÐЧµÄ°i¨¨DÔÚÄaÈÏΪÓÐÏÓÒɵijÌÐo´¦Àiºo´oÓ¡×Öu´®µÄÄÚÂe¡£Í¨¹ý´oÓ¡×Öu´®µÄÄÚÂe£¬Äa¿ÉÒÔ¢ÏÖʲôʱºoÖÐÎÄ×Öu±»×ª»»³É Unicode£¬Ê²Ã´Ê±ºoUnicode ±»×ª»ØÖÐÎÄÄÚÂe£¬Ê²Ã´Ê±ºoÒ»¸oÖÐÎÄ×Ö³ÉÁËÁ½¸o Unicode ×Öu£¬Ê²Ã´Ê±ºoÖÐÎÄ×Öu´®±»×ª³ÉÁËÒ»´®Îʺţ¬Ê²Ã´Ê±ºoÖÐÎÄ×Öu´®µÄ¸ßλ±»½ØµoÁË¡¡
È¡ÓúÏÊʵÄÑu±¾×Öu´®Ò²ÓÐÖuÓÚÇøÖÎÊÌaµÄÀaÐÍ¡£È磺"aa°¡ aa?@aa" µÈÖÐÓ¢Ïa¼a£¬GB¡¢GBKÌØÕ÷×Öu¾uÓеÄ×Öu´®¡£Ò»°aÀ´Ëµ£¬Ó¢ÎÄ×Ö*uÎÞÂÛÔoôת»»»o´¦Ài£¬¶¼²»»aʧÕae(Èç¹uÓoµ½ÁË£¬¿ÉÒÔ³¢ÊÔ×ÅÔo¼ÓÁ¬ÐøµÄÓ¢ÎÄ×Öĸ³¤¶È)¡£
½a¾o¸÷ÖÖÓ¦ÓõÄÂÒÂeÎÊÌa
Çe×¢ÒaÊÇÊoÓÚ HTML ÐÅÏ¢µÄ£¬½o½oÊÇÒ»¸oÉuÃ÷£¬½o±iÃ÷*þÎñÆ÷ÒѾ°Ñ HTML ÐÅÏ¢´«µ½ÁËa¯ÀÀÆ÷¡£
http ±eÍÊÇþÎñÆ÷ÒÔ http ÐÒe´«ËÍ HTML ÐÅÏ¢µ½a¯ÀÀÆ÷Ç°ËuËͳoµÄ×Ö´®¡£¶ø ±eÇ(C)ÊÇÊoÓÚ HTML ÐÅÏ¢µÄ£¬ËuÒÔ header() ¢Ë͵ÄÄÚÈÝÏȵ½´ia¯ÀÀÆ÷£¬Í¨Ë×µa¾ÍÊÇ header() µÄÓÅÏȼ¶¸ßÓÚ (²»ÖªµÀ¿É²»¿ÉÒÔÕaÑu½²)¡£¼ÙÈçÒ»¸o php Ò³Ãae¼ÈÓÐheader("content-type:text/html;charset=xxx")£¬ÓÖÓУ¬a¯ÀÀÆ÷¾ÍÖ»ÈÏÇ°Õß http ±eͶø²»ÈÏ meta ÁË¡£µ±È»Õa¸oº¯ÊýÖ»ÄÜÔÚ php Ò³ÃaeÄÚʹÓá£
ͬÑuÒ²ÁoÓÐÒ»¸oÎÊÌa£¬ÎªÊ²Ã´Ç°Õ߾;ø¶ÔÆð×÷Ó㬶øºoÕßÓÐʱºo¾Í²»ÐÐÄØ?Õa¾ÍÊǽÓÏÂÀ´ÒªÌ¸µÄApache µÄÔÒoÁË¡£
ÓÃÎı¾±a¼Æ÷´o¿ª httpd.conf£¬µÚ 708 ÐÐ(²»Í¬°ae±¾¿ÉÄܲ»Í¬)ÓÐ AddDefaultCharset xxx£¬xxxΪ±aÂeÃu³Æ¡£ÕaÐдuÂeµÄÒa˼£ºÉeÖÃÕu¸oþÎñÆ÷ÄÚµÄÍøÒ³Îļþ http ±eÍÀiµÄ×Öu¼¯ÎªÄaĬÈ쵀 xxx×Öu¼¯¡£ÓÐÕaÐУ¬¾ÍÏaµ±ÓÚ¸øÿ¸oÎļþ¶¼¼ÓÁËÒ»ÐÐ header("content-type:text/html; charset=xxx")¡£ÕaϾÍÃ÷°×ΪʲôÃ÷Ã÷ÉeÖÃÁËÊÇ utf-8£¬¿Éa¯ÀÀÆ÷ʼÖÕ²ÉÓà gb2312 µÄÔÒo¡£
Èç¹uÍøÒ³ÀiÓÐ header("content-type:text/html; charset=xxx")£¬¾Í°ÑĬÈϵÄ×Öu¼¯¸ÄΪÄaÉeÖõÄ×Öu¼¯£¬ËuÒÔÕa¸oº¯ÊýÓÀÔ¶ÓÐÓá£Èç¹u°Ñ AddDefaultCharset xxx Ç°Ãae¼Ó¸o"#"£¬×¢Ê͵oÕa¾a£¬¶øÇÒÒ³ÃaeÀi²»º¬ header("content-type¡")£¬ÄÇÕa¸oʱºo¾ÍÂÖµ½ meta ±eÇ(C)Æð×÷ÓÃÁË¡£
ÏÂÃaeÁгoÒÔÉϵÄÓÅÏÈ˳Ðo£º
.. header("content-type:text/html; charset=xxx")
.. AddDefaultCharset xxx
..
Èç¹uÄaÊÇ web ³ÌÐoÔ±£¬½¨Òe¸øÄaµÄÿ¸oÒ³Ãae¶¼¼Ó¸oheader("content-type:text/html;charset=xxx")£¬ÕaÑu¾Í¿ÉÒÔ±£Ö¤ËuÔÚÈκÎþÎñÆ÷¶¼ÄÜÕýÈÏÔʾ£¬¿ÉÒÆÖ²ÐÔÒ²±È½ÏÇ¿¡£
½aÊøÓi
Æaʵphp¿ª¢ÖеÄÖÐÎıaÂe²¢Ã»ÓÐÏeÏñµÄÄÇô¸´ÔÓ£¬ËaÈ»¶¨Î»ºÍ½a¾oÎÊÌaûÓж¨¹ae£¬¸÷ÖÖÔËÐл¾³Ò²¸÷²»¾¡È»£¬µ«ºoÃaeµÄÔÀiÊÇÒ»ÑuµÄ¡£Á˽a×Öu¼¯µÄ֪ʶÊǽa¾o×ÖuÎÊÌaµÄ»u´¡¡£²»¹ý£¬Ëae×ÅÖÐÎÄ×Ö*u¼¯µÄ±a»¯£¬²»½o½oÊÇ php ±a³Ì£¬ÖÐÎÄÐÅÏ¢´¦ÀiÖеÄÎÊÌa»¹ÊÇ»a´aeÔÚÒ»¶Îʱ¼aµÄ¡£