在這一個小的幫助,這裏有它的細節PHP和MySQL忽略存在於數據庫中的特殊chracters
[Products]
id int
name text
category
color
問題是色域值,樣本值是:
GOLDRED
GOLD-RED
GOLD/RED
BLUE/GREEN-RED
WHITE GOLD-YELLOW/ORANGE
我可以很乾淨的搜索查詢,如使用基本功能
"select * from products where color=".cleanstring($stringval)." limit 1";
function cleanstring($var) {
$newtext = $var;
$newtext = preg_replace("/[^a-zA-Z0-9\s]/", "", $newtext);
$newtext = str_replace(" ", "", $newtext);
$newtext = strtoupper($newtext);
return $newtext;
}
問題這個樣本是與內容。這是成千上萬的記錄,沒有任何形式的標準使用命名約定。
我想選擇這些記錄的值與我的cleanstring()
相似。
實施例:
Query = GOLDRED
可以選擇
GOLD-RED
GOLD RED
GOLDRED
GOLD/RED
GOLDRED
任何您可以推薦的解決方案?代碼在PHP/MySQL中。
你試過'LIKE'條款'LIKE「%GOLDRED%」' – 2013-04-27 03:31:44
我已經試過了,問題就這樣,就是它不能選擇那些超過和斜線和空格。 – user2173176 2013-04-27 03:38:29
不是很熟悉mysql中的'soundex()'函數,但是你試過了嗎? – 2013-04-27 03:42:41