ThinkPHP统一设置utf-8编码

1.项目编码

在编辑器中设置编码utf-8

2.在浏览器中设置编码

//Thinkphp方法中添加header设置utf-8只有index方法解决了乱码
class UserAction extends CommonAction{
  function index(){

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

    echo"你好";

  }

  function add(){

    echo "添加";

  }
 }
3.解决方法定义Common控制器在其中定义 _initialize方法
UserAction继承CommonAction
<?php

class CommonAction extends Action{

    function _initialize(){

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

      

    }

}

?>

所有新建的的Action继承CommonAction就可以实现统一UTF-8编码



你可能感兴趣的:(thinkphp)