Two Solutions for Chinese Scrambling in CodeIgniter Output

  • 2021-06-29 10:26:18
  • OfStack

When controller directly echo, some browsers will encounter garbled code.There are two ways to solve this problem:

1. Common header functions of php

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

Example:

<?php
class home extends CI_Controller {
 function index()
 {
 // Set Encoding 
 header("Content-type:text/html;charset=utf-8");
 echo ' Test Output ';
 }
}
?>

2. Use Output class to solve

$this->output->set_content_type('application/html;charset=utf-8');
$this->output->set_output(" Test Output ");


Related articles: