存储在MYSQL中的中文字符不会显示在CI中

时间:2014-06-20 06:25:03

标签: php mysql codeigniter utf-8 utf8-decode

我的mysql字段为collat​​ion - utf8_general_ci,当我输入中文字符并提交表单时,它会很好地存储到数据库中,但是当它在视图页面中显示时格式不同。以下是我用过的设置

在config.php中

$config['charset'] = 'UTF-8';

在database.php中

$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';

我的HTML标头元标记是

<meta http-equiv="Content-Type" content="text/html;charset=utf-8" ></meta>

虽然我配置了所有可能性

中文字符显示为

  

ÃÂÂÂÂÂÂÂÂÂÂÂÂÂÂ¥|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| “Ã|›Â'Ã|–°的¥â€ºÂ½Ã¥Â®Â¶Ã§Å¡â€ZA©â€|‹é•¿å’埃'å••••••••â€â€â€â€â€â€ AA¥â€~¨ä¸â,¬Ã|¬¡çšâ€ZA¥A“¨çº¿ç›®å½À¢Ã£â ,¬â€The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The The ¤ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ¥••†|Ã|‹¬ä¸–ç•Å'许多Ã|â€Â¿Ã¥ÂºÅ“作䠸ºè¢«è®¤ä¸ºÃ|˜¯å®žçâ€Â¨Ã¯Â¼Å'Ã|œ‰äº›äºº |²¡Ã|œ‰Ã|£A¥Â¼Â被美国Ã|‰¿è®¤ã€央行€SA¥ ˆ¶åºÂ|与

db中的其他位置存储为

  

中央情报局出版和更新国家的酋长和外国政府的内阁成员每周一次的在线目录。该目录的目的是将主要作为参考援助和包括世界许多政府作为被认为是实用,有些人没有正式被美国承认。制度与

我还在视图页面中尝试了utf8_decode();,但它也无效。 谁能建议我一个解决方案。提前谢谢。

1 个答案:

答案 0 :(得分:1)

我已经包括在内 mb_internal_encoding('UTF-8'); header('Content-type: text/html; charset=UTF-8') ; 在标题中

现在工作正常。 谢谢你的评论。