我很難創建一個函數,它會檢查數據庫中是否存在「字符串」,然後再添加它,如果不是,那麼它將爆炸字符串並找到匹配的字符串。這是我做的,但錯過了它找到一個數組或字符串中的匹配字符串
更新信息:我有這個問題,我比較輸入值與數據庫值。
$ database =「我是; $輸入=」我「當我比較兩個使用下面的函數出來空作爲未找到項目但當我嘗試重置$ input =我是」,那麼ofcourse發現商品。甚至與string_replace是basicly取出任何兩個數值不字母或數字。我需要幫助PLZ
//string_replace is to replace all spaces and special chars with ""
public function match_string(){
$name = $this->string_replace($this->name);
$all_item = $this->find_all(); // find_all is to fetch all data from mysql table
foreach($all_item as $item){
$lowercase = $this->string_replace($item->name);
if($lowercase == $name){
// match found
}elseif($item_explode=explode(" ",$item->name)){
$name_explode = explode(" ",$this->name);
foreach($name_explode as $key){
if(in_array($key,$item_explode)){
//match key found
}
}
}
}
}
我試圖使用strpos,但我不斷收到空分隔符的錯誤 – user3311125