CodeIgniter輸出中文亂碼的兩種解決辦法

2013-04-18 15:48:00來源:西部e網(wǎng)作者:

在controller直接echo的時候,某些瀏覽器會出現(xiàn)亂碼的情況?梢杂孟旅鎯煞N方法解決:

在controller直接echo的時候,某些瀏覽器會出現(xiàn)亂碼的情況?梢杂孟旅鎯煞N方法解決:

1、常用的php的header函數(shù)

header("Content-type:text/html;charset=utf-8");

示例:

<?php
class home extends CI_Controller {
 function index()
 {
 //設(shè)置編碼
 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("測試輸出");

關(guān)鍵詞:CodeIgniter亂碼

贊助商鏈接: