我想通過星號將字符串與另一個字符串進行匹配。匹配帶星號的字符串
例子:我有
$var = "*world*";
我想打一個函數,要麼返回true或false,以配合我的字符串。 不區分大小寫
example:
match_string("*world*","hello world") // returns true
match_string("world*","hello world") // returns false
match_string("*world","hello world") // returns true
match_string("world*","hello world") // returns false
match_string("*ello*w*","hello world") // returns true
match_string("*w*o*r*l*d*","hello world") // returns true
的*只會在範圍內匹配任何字符。我嘗試使用preg_match幾個小時沒有運氣。
什麼是你最後一次嘗試? – 2011-04-11 13:35:16
我最後一次嘗試是用*(*)替換*以使用preg_match,但不知道我犯了什麼錯誤。 – TDSii 2011-04-11 13:43:16
你從哪裏得到字符串?爲什麼不使用「正常」正則表達式? – 2011-04-11 13:43:33