Php Codeigniter中的JQuery自动完成编码
这适用于英语字符,但不适用于阿拉伯语。我为Php Codeigniter中的JQuery自动完成编码,php,mysql,jquery-ui,codeigniter,autocomplete,Php,Mysql,Jquery Ui,Codeigniter,Autocomplete,这适用于英语字符,但不适用于阿拉伯语。我为$title打印了带有“فف”的查询,我在其中发现了如下奇怪字符: SELECT * FROM users WHERE agent_id = 1 AND type LIKE "owner" AND (firstName LIKE "%\%D9\%81\%D9\%81%" OR lastName LIKE "%\%D9\%81\%D9\%81%") 这是我的密码: 控制器: public function getResultExtend($title)
$title
打印了带有“فف”的查询,我在其中发现了如下奇怪字符:
SELECT * FROM users WHERE agent_id = 1 AND type LIKE "owner" AND (firstName LIKE "%\%D9\%81\%D9\%81%" OR lastName LIKE "%\%D9\%81\%D9\%81%")
这是我的密码:
控制器:
public function getResultExtend($title) {
$user_id = $this->session->userdata('id');
$result = $this->user->getOwners($user_id, $title);
foreach ($result as $user) {
$user->userName = utf8_encode(stripslashes($user->userName));
}
echo json_encode($result);
}
视图:
型号:
function getOwners($user_id, $title) {
header('Content-Type:text/html; charset=UTF-8');
//$title = iconv(mb_detect_encoding($title, mb_detect_order(), true), "UTF-8", $title);
$q = $this->db->query('SET NAMES utf8');
$query = $this->db->query('SELECT * FROM users
WHERE agent_id = ' . $user_id . ' AND type LIKE "owner"
AND (firstName LIKE "%'.$this->db->escape_like_str($title).'%"
OR lastName LIKE "%'.$this->db->escape_like_str($title).'%")
');
return $query->result();
}
我的表排序规则是utf8\u unicode\u ci,列也是utf-8。
那么,问题出在哪里?检查应用程序/config/database.php中的行:
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
同时尝试添加.htaccess
AddDefaultCharset UTF-8
或者直接添加到index.php
header('Content-type: text/html; charset=utf-8' );
完成,但什么也没发生:(在PHPMyAdmin中尝试查询后,我发现它工作正常。
header('Content-type: text/html; charset=utf-8' );