Home  >  Article  >  Backend Development  >  CodeIgniter输出中文乱码的两种解决办法_php实例

CodeIgniter输出中文乱码的两种解决办法_php实例

WBOY
WBOYOriginal
2016-06-07 17:19:07685browse

在controller直接echo的时候,某些浏览器会出现乱码的情况。可以用下面两种方法解决:

1、常用的php的header函数

复制代码 代码如下:
header("Content-type:text/html;charset=utf-8");

示例:

复制代码 代码如下:
class home extends CI_Controller {
 function index()
 {
 //设置编码
 header("Content-type:text/html;charset=utf-8");
 echo '测试输出';
 }
}
?>

2、使用Output类来解决

复制代码 代码如下:
$this->output->set_content_type('application/html;charset=utf-8');
$this->output->set_output("测试输出");
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn