2014-02-14 95 views
0

我很難創建一個函數,它會檢查數據庫中是否存在「字符串」,然後再添加它,如果不是,那麼它將爆炸字符串並找到匹配的字符串。這是我做的,但錯過了它找到一個數組或字符串中的匹配字符串

更新信息:我有這個問題,我比較輸入值與數據庫值。

$ 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 
      } 
     } 
    } 
    } 
} 

回答

0

在php中檢查一個字是否在字符串中,使用

if (strpos($word, $my_string) !== false) 
{ 
    echo 'Word found'; 
} 
+0

我試圖使用strpos,但我不斷收到空分隔符的錯誤 – user3311125

-1

string_replace不是在PHP函數,你應該使用str_replace方法,在這裏找到:http://us3.php.net/str_replace

+1

'string_replace'是由OP創建的函數。 – ojovirtual

+0

我猜'string_replace'是OP類的一個方法。 –

+0

函數string_replace是自己創建的函數,用於刪除所有空格和特殊字符。 – user3311125

相關問題