thinkphpÉèÖÃÖÐÎÄÂÒÂëÔõô½â¾ö
thinkphpÊÇÒ»¿îÓÅÒìµÄphp¿ò¼Ü£¬ÆÕ±éµØÓ¦ÓÃÓÚwebÓ¦ÓõĿª·¢ÖС£È»¶ø£¬ÔÚʹÓÃthinkphp¾ÙÐпª·¢Àú³ÌÖУ¬ºÜÈÝÒ×·ºÆðÖÐÎÄÂÒÂëµÄÎÊÌâ¡£±¾ÎĽ«ÏÈÈÝÔÚthinkphp¿ò¼ÜÏÂÔõÑù½â¾öÖÐÎÄÂÒÂëÎÊÌâ¡£
×Ö·û¼¯ÉèÖÃ
ÔÚThinkPHP¿ò¼ÜÖУ¬¿ÉÒÔÔÚÓ¦ÓÃĿ¼ÏµÄconfig.phpÎļþÖÐÉèÖÃ×Ö·û¼¯¡£ÔÚÎļþÖÐËÑË÷’charset’Òªº¦×Ö£¬¿ÉÒÔÕÒµ½ÈçÏÂÄÚÈÝ£º
'charset' => 'utf-8',
µÇ¼ºó¸´ÖÆ
¿ÉÒÔ¿´µ½£¬ThinkPHPĬÈϵÄ×Ö·û¼¯ÊÇutf-8¡£ÈôÊÇÔÚä¯ÀÀÆ÷ÖУ¬Ò³ÃæµÄmeta±êÇ©Ö¸¶¨ÁË×Ö·û¼¯£¬ÄÇô¾ÍÐèÒª¼á³ÖÒ»Ö¡£ÀýÈ磬ÔÚHTML´úÂëÖÐÖ¸¶¨ÁË×Ö·û¼¯ÎªGB2312£¬ÄÇô¾ÍÐèÒªÔÚconfig.phpÖÐÉèÖÃ×Ö·û¼¯ÎªGB2312:
'charset' => 'GB2312',
µÇ¼ºó¸´ÖÆ
Êý¾Ý¿â²Ù×÷×Ö·û¼¯ÉèÖÃ
ÔÚʹÓÃThinkPHP¾ÙÐÐÊý¾Ý¿â²Ù×÷ʱ£¬ÐèÒªÉèÖÃÊý¾Ý¿âµÄ×Ö·û¼¯¡£¿ÉÒÔÔÚdatabase.phpÎļþÖÐÉèÖãº
'charset' => 'utf8',
µÇ¼ºó¸´ÖÆ
ÈôÊÇÊý¾Ý¿âÉèÖõÄ×Ö·û¼¯ºÍ¿ò¼ÜÉèÖõÄ×Ö·û¼¯·×ÆçÖ£¬ÄÇô¾ÍÐèÒª¾ÙÐÐÏìÓ¦µ÷½â¡£
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
Îļþ±àÂë
ÔÚʹÓÃThinkPHP¿ò¼Ü¾ÙÐÐÎļþµÄ±àдʱ£¬ÐèÒª¼á³ÖÎļþ±àÂëºÍ¿ò¼ÜÉèÖõÄ×Ö·û¼¯Ò»Ö¡£ÈôÊÇʹÓõÄÊÇutf-8±àÂ룬ÄÇôÎļþµÄ¿ªÍ·Ó¦¸ÃÉèÖÃΪ£º
header("Content-type: text/html; charset=utf-8");
µÇ¼ºó¸´ÖÆ
Õâ¾ä»°¿ÉÒÔÈ·±£Êä³öµÄÄÚÈÝΪutf-8±àÂë¡£
Êý¾Ý¿â±íÉèÖÃ
ÔÚʹÓÃThinkPHP¿ò¼Ü¾ÙÐÐÊý¾Ý¿â²Ù×÷ʱ£¬ÐèÒªÉèÖöÔÓ¦µÄÊý¾Ý±íµÄ×Ö·û¼¯¡£¿ÉÒÔÔÚ½¨±íÓï¾äÖÐʹÓÃcharset²ÎÊý£¬ÀýÈ磺
CREATE TABLE `user` ( `id` int(11) NOT NULL AUTO_INCREMENT, `username` varchar(20) NOT NULL COMMENT 'Óû§Ãû', `password` varchar(50) NOT NULL COMMENT 'ÃÜÂë', `email` varchar(50) NOT NULL COMMENT 'ÓÊÏä', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Óû§±í';
µÇ¼ºó¸´ÖÆ
¿ÉÒÔ¿´µ½£¬ÔÚ½¨±íÓï¾äÖÐÖ¸¶¨ÁË×Ö·û¼¯Îªutf-8¡£
ÖÐÎıàÂëÃûÌÃת»»
ÓÐʱ¼ä£¬ÎÒÃÇÐèÒª´ÓGB2312±àÂëÃûÌÃת»»µ½utf-8±àÂëÃûÌ㬻òÕß·´¹ýÀ´¡£¿ÉÒÔʹÓÃiconv()º¯Êý¾ÙÐÐת»»£º
iconv("utf-8","gb2312",$str); iconv("gb2312","utf-8",$str);
µÇ¼ºó¸´ÖÆ
ÕâÑù¾Í¿ÉÒÔ¾ÙÐвî±ð±àÂëÃûÌÃÖ®¼äµÄת»»ÁË¡£
×ܽ᣺
ÔÚʹÓÃThinkPHP¾ÙÐпª·¢Ê±£¬·ºÆðÖÐÎÄÂÒÂëµÄÎÊÌâÍùÍùÊÇÓÉÓÚ×Ö·û¼¯ÉèÖò»×¼È·µ¼Öµġ£ÔÚÉÏÊö5¸ö·½Ãæ¾ÙÐÐÊʵ±µ÷½âºÍÉèÖ㬾ͿÉÒԺܺõؽâ¾öÖÐÎÄÂÒÂëÎÊÌâ¡£
ÒÔÉϾÍÊÇthinkphpÉèÖÃÖÐÎÄÂÒÂëÔõô½â¾öµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡