thinkphp 分頁編碼出錯 致使第二頁分頁sql查詢亂碼

點擊第二頁的時候 url 傳值 變爲gbk 致使sql 亂碼
sql

程序和數據庫編碼都是utf8.   
數據庫

如下是解決方案。
this

$keyword = $this->_param('key');編碼

    //mb_check_encoding 檢查字符串在指定的編碼裏是否有效url

    //成功時返回 TRUE, 或者在失敗時返回 FALSE。  spa

    //mb_check_encoding([ string $var = NULL [ , string  $encoding = mb_ubternal_encoding() ] ]  );
code

if (!mb_check_encoding($keyword, 'utf-8')){utf-8

    // iconv字符串按要求的字符編碼來轉換字符串

    // string iconv (string $in_chatset , string $out_chatset , string $str )string

    // $in_chatset 輸入的字符集  $out_chatset 輸出的字符集  $str 要轉換的字符串

    $keyword = iconv('gbk', 'utf-8', $keyword);}

相關文章
相關標籤/搜索