我正在尝试将字符串中的某些短语作为单词匹配(stristr 不起作用,因为我不想要包含“单词”的结果)
我使用这段代码:
function striword($string, $word) {
return preg_match("/(?:[[:space:]]|^)" . $word . "(?:[^\w]|$)/i", $string);
}
但是当我尝试匹配像“这是一个字符串”这样的字符串时,它不能按预期工作:(
例子:
//Phrase to match: "soda and beer"
striword($string, "soda and beer");
String 1: "I like soda and beer" MATCH: TRUE
String 2: "I like soda and beerbum" MATCH: FALSE
String 3: "I like soda and beer, it's nice!" MATCH: TRUE