thinkphpÒ³Ãæ·¿ªÂÒÂë
ÈôÊÇÄãÔÚʹÓà thinkphp ¿ò¼Ü¿ª·¢ÍøվʱÓöµ½ÁËÒ³Ãæ·¿ªÂÒÂëµÄÎÊÌ⣬ÄÇô¿ÉÄÜÊÇÓÉÓÚ¶àÖÖÔµ¹ÊÔÓɵ¼Öµġ£ÔÚÕâƪÎÄÕÂÖУ¬ÎÒ½«ÏÈÈÝһЩ¿ÉÄܵĽâ¾öÒªÁì¡£
¼ì²é±àÂëÃûÌÃ
Ê×ÏÈ£¬ÐèÒª¼ì²éÔÚÄãµÄ PHP ÎļþÖÐÖ¸¶¨µÄ±àÂëÃûÌÃÊÇ·ñ׼ȷ¡£ÔÚ ThinkPHP ÖУ¬Ä¬ÈÏʹÓà UTF-8 ±àÂëÃûÌã¬ÈôÊÇÄãÔÚÎļþÍ·ÖÐÖ¸¶¨Á˲î±ðµÄ±àÂëÃûÌã¬ÄÇô»áµ¼ÖÂÂÒÂëµÄÎÊÌâ¡£Äã¿ÉÒÔÔÚÎļþÍ·ÖÐʹÓÃÒÔÏ´úÂëÖ¸¶¨±àÂëÃûÌãº
header("Content-type: text/html; charset=utf-8");
µÇ¼ºó¸´ÖÆ
ÈôÊÇÄãʹÓõÄÊÇÆäËû±àÂëÃûÌã¬ÄãÐèÒªÔÚ header() º¯ÊýÖÐÖ¸¶¨ÏìÓ¦µÄ²ÎÊý¡£
¼ì²éЧÀÍÆ÷ÉèÖÃ
ÁíÒ»¸ö¿ÉÄܵÄÎÊÌâÊÇЧÀÍÆ÷ÉèÖò»×¼È·¡£ÄãÐèÒª¼ì²éЧÀÍÆ÷ÊÇ·ñ׼ȷµØÉèÖÃÁË×Ö·û±àÂë¡£Äã¿ÉÒÔʵÑéÔÚ php.ini ÎļþÖÐÌí¼ÓÒÔÏ´úÂ룺
default_charset = "utf-8"
µÇ¼ºó¸´ÖÆ
È·±£ÉúÑIJ¢ÇÒÖØÆôЧÀÍÆ÷ºóÉúЧ¡£ÈôÊÇÄãÎÞ·¨»á¼û php.ini Îļþ£¬ÄÇôÄãÒ²¿ÉÒÔʵÑéÔÚ .htaccess ÎļþÖÐÌí¼ÓÒÔÏ´úÂ룺
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
AddDefaultCharset utf-8
µÇ¼ºó¸´ÖÆ
¼ì²éÊý¾Ý¿â±àÂë
ÈôÊÇÄãµÄÍøվʹÓÃÁËÊý¾Ý¿â£¬ÄÇôÄãÒ²ÐèÒª¼ì²éÊý¾Ý¿âµÄ±àÂëÃûÌá£ÔÚ ThinkPHP ÖУ¬Ä¬ÈÏʹÓà UTF-8 ±àÂëÃûÌã¬ÈôÊÇÄãÔÚÊý¾Ý¿âÖÐʹÓÃÁËÆäËû±àÂëÃûÌã¬ÄÇô»áµ¼ÖÂÂÒÂëµÄÎÊÌâ¡£Äã¿ÉÒÔÔÚÉèÖÃÎļþÖÐÖ¸¶¨Ãü¾Ý¿â±àÂëÃûÌã¬ÀýÈ磺
'params' => [ PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8', ],
µÇ¼ºó¸´ÖÆ
È·±£ÉúÑIJ¢ÇÒÖØÆôЧÀÍÆ÷ºóÉúЧ¡£
¼ì²éä¯ÀÀÆ÷ÉèÖÃ
×îºó£¬ÄãÐèÒª¼ì²éÄãµÄä¯ÀÀÆ÷ÉèÖÃÊÇ·ñ׼ȷ¡£ÔÚä¯ÀÀÆ÷ÖУ¬Ñ¡Ôñ¡°Éó²é-±àÂ롱²Ëµ¥£¬È·±£Ñ¡ÔñÁË׼ȷµÄ±àÂëÃûÌã¬ÀýÈç UTF-8¡£
×ܽá
ÔÚʹÓà ThinkPHP ¿ò¼Ü¿ª·¢Íøվʱ£¬ÈôÊÇÄãÓöµ½ÁËÒ³Ãæ·¿ªÂÒÂëµÄÎÊÌ⣬ÄÇôÐèÒª¼ì²é±àÂëÃûÌá¢Ð§ÀÍÆ÷ÉèÖá¢Êý¾Ý¿â±àÂëºÍä¯ÀÀÆ÷ÉèÖõȶà¸ö·½Ã棬ÕÒµ½ÎÊÌâËùÔÚ²¢¾ÙÐнâ¾ö¡£ÈôÊÇÒÔÉÏÒªÁì¾ùÎÞЧ£¬¿ÉÒÔ˼Á¿Ê¹ÓÃһЩµ÷ÊÔ¹¤¾ßÀ´½øÒ»²½ÅÅÅÌÎÊÌâ¡£
ÒÔÉϾÍÊÇthinkphpÒ³Ãæ·¿ªÂÒÂëµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡