转载 

解决 ThinkPHP URL 中文乱码问题

分类:    852人阅读    IT小君  2015-01-29 23:20
解决 ThinkPHP URL 中文乱码问题
将GetcodingBehavior.class.php放入/Lib/Behavior中

/Conf/tags.php 加入 "app_begin" => array("Getcoding")

<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of GetcodingBehavior
 *
 * @author Administrator
 */

/** * $_GET 编码 解决url中文问题  * @author Administrator  *  */
class GetcodingBehavior extends Behavior {

    public function run(&$params) {
        foreach ($_GET as $k => $v) {
            if (!is_array($v)) {
                if (!mb_check_encoding($v, \'utf-8\')) {
                    $_GET[$k] = iconv(\'gbk\', \'utf-8\', $v);
                }
            } else {
                foreach ($_GET[\'_URL_\'] as $key => $value) {
                    if (!mb_check_encoding($value, \'utf-8\')) {
                        $_GET[\'_URL_\'][$key] = iconv(\'gbk\', \'utf-8\', $value);
                    }
                }
            }
        }
    }

}

支付宝打赏 微信打赏

如果文章对你有帮助,欢迎点击上方按钮打赏作者

 工具推荐 更多»