Home >php教程 >php手册 >搜索分页中文乱码解决方法,已验证可以用

搜索分页中文乱码解决方法,已验证可以用

WBOY
WBOYOriginal
2016-06-07 11:36:511457browse

一般搜索中文,分页后通过get传递参数会造成中文乱码,这边网上找到了解决方法,共享一下。
//解决分页中文乱码问题
$key = $this->_param('key');
if (!mb_check_encoding($key, 'utf-8')){
$key = iconv('gbk', 'utf-8', $key);
}


ThinkPHP\Lib\Behavior这个路径里面建立一个文件GetcodingBehavior.class.php

代码如下:
/**
* $_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);
}
}
}
}

}
}

AD:真正免费,域名+虚机+企业邮箱=0元

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