Home  >  Article  >  Backend Development  >  Two solutions to how CodeIgniter outputs Chinese garbled characters_PHP tutorial

Two solutions to how CodeIgniter outputs Chinese garbled characters_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:28:30842browse

When the controller echoes directly, some browsers will have garbled characters. You can use the following two methods to solve it:

1. Commonly used PHP header functions

Copy code The code is as follows:
header ("Content-type:text/html;charset=utf-8");

Example:

Copy code The code is as follows:
class home extends CI_Controller {
function index()
{
//Set encoding
header("Content-type:text/html;charset=utf-8");
echo 'test output';
}
}
?>

2. Use the Output class to solve the problem

Copy code The code is as follows:
$this->output->set_content_type('application/html;charset=utf-8 ');
$this->output->set_output("Test Output");

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/788623.htmlTechArticleWhen the controller echoes directly, some browsers will have garbled characters. You can use the following two methods to solve the problem: 1. Commonly used PHP header function. Copy the code. The code is as follows: header(...
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