如果我查看war
,如果我查看Award
,我会发现 $title = "Music award";
if (strpos($title, 'war') !== false) {
echo "found";
}
:
war
如果我查找award
,我不想找到{{1}}
答案 0 :(得分:1)
使用正则表达式匹配
$title = "Music award";
if (preg_match('/\bwar\b/', $title) !== false) {
echo "found";
}
答案 1 :(得分:0)
<?php
$string = "We are the music makers and we are the dreamers of dreams.";
$words = str_word_count($string, 1);
var_dump(in_array('music', $words));
var_dump(in_array('dream', $words));
输出:
bool(true)
bool(false)