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

WBOY
Release: 2016-06-07 17:19:07
Original
759 people have browsed it

在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("测试输出");
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!