在controller直接echo的时候,某些浏览器会出现乱码的情况。可以用下面两种方法解决:
1、常用的php的header函数
1 | header( "Content-type:text/html;charset=utf-8" ); |
示例:
01 | <?php |
02 | class home extends CI_Controller { |
03 | function index() |
04 | { |
05 | //设置编码 |
06 | header( "Content-type:text/html;charset=utf-8" ); |
07 | echo '测试输出' ; |
08 | } |
09 | } |
10 | ?> |
2、使用Output类来解决
1 | $this ->output->set_content_type( 'application/html;charset=utf-8' ); |
2 | $this ->output->set_output( "测试输出" ); |