我想通过星号将字符串与另一个字符串进行匹配。匹配带星号的字符串
例子:我有
$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