我有 2 个 mysql 表 property
和 building
。在 property
表中,我有一个名为 unitnumber
的字段,该字段中的值类似于 1a
、2b
等。在 building
表中,我有一个名为 address
的字段,它采用 PHP 的
urlencoded
格式。该值类似于 26+Dovedale+Place%2C+Parnell
现在我想实现一个搜索功能,这样当用户键入 1a, 26 Dovedale
时,我需要从数据库中提取结果。
目前已实现:
$keyword = preg_replace('/[^a-zA-Z0-9-]/', '', $_REQUEST['keyword']);
$keyword = str_replace(" ", "-", $keyword);
$a->rqNotEmpty('keyword', $keyword);
$query = "SELECT * FROM `buildings` b left join properties p on p.buildingId=b.id
WHERE concat(p.floor,p.number,b.address) LIKE '%".$keyword."%'
or concat(p.number,p.floor,b.address) LIKE '%".$keyword."'";
但现在的问题是,当我准备 $keyword
变量时,我将得到类似 1a26Dovedale
的内容,并且在 CONCAT
之后的数据库中,该值将类似于 1a26+Dovedale+Place%2C+Parnell
。我无法对 $keyword 进行 urlencode,因为数据库不是标准化形式。数据库地址之间有 2 个空格。那么有没有办法urldecode
mysql字符串??我在这里处理近 400 万条记录!!
最佳答案
您可以尝试安装 MySQL UDF(用户定义函数)以在 MySQL 中提供 urlencode()
和 urldecode()
函数。这是链接:http://freecode.com/projects/libmysqludf
关于php - 处理mysql中的特殊字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11680039/