这就是我现在拥有的:
$text = "test";
$count = substr_count($text, "Hello Everyone this is a
test test test that im testing");
值$count为4。我想说3,因为测试这个词和测试不一样。如果更好/更容易的话,我愿意使用正则表达式来做这件事?有什么建议请
在preg_match_all()
:中使用单词边界转义序列'b
$count = preg_match_all('/'btest'b/', "Hello Everyone this is a
test test test that im testing");
另请参阅:转义序列