tp框架下,数据库和编辑器都是utf-8, 输出中文却还是乱码

输出:

array(2) { [0]=> array(4) { ["id"]=> string(1) "1" ["user"]=> string(6) "鏄悧"  ##乱码

 

说明: PHPstudy集成环境中的nts(非线性安全)下,在window本地是禁止路由的,但是PHP5.6版本以下,中文输出会乱码。

http://www.tp.com/index.php/Home/User/model

例如上面的url, 你想省略掉index.php,毕竟懒人都不想写太长的url, 

如果是用 nts模式 的PHP版本,因为它禁止路由, 所以你去掉index.php就会报错, 如下:
No input
file specified.

 

所以, 解决方法有两个:

1),选择版本PHP5.6以上的这两个版本;如下图

 

2),在tp框架的controller基类声明字符编码;

<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2014 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
namespace Think;

// phpstudy环境下,如果是NTS(非线性安全)会是乱码
header("content-type:text/html; charset=utf-8"); ## 就加多这一句即可

/**
 * ThinkPHP 控制器基类 抽象类
 */
abstract class Controller {

    /**
     * 视图实例对象
     * @var view
     * @access protected
     */    
    protected $view     =  null;

   。。。。。。

}

 

效果好了如下:

array(2) { [0]=> array(4) { ["id"]=> string(1) "1" ["user"]=> string(6) "是吗"  。。。 ##正常

 结果: 因为我既需要路由(既不是nts模式的PHP版本), 又需要中文输出正常, 所以我选择第二种方式。

posted @ 2018-11-28 17:01  一粒小米-博客  阅读(776)  评论(0编辑  收藏  举报