我在搜索文本中的特定单词时遇到困难。我尝试使用该stripos方法,但它抛出一个错误,因为文本返回的是一个对象:$text = preg_replace("/note:/" ,'' , $text);if(stripos($text, "note:") !== false){ return true}如果字符串在文本中包含要在我的if.
1 回答
红糖糍粑
TA贡献1815条经验 获得超6个赞
也许,我们并不需要一个preg_replace和strpos就足够了:
$text = 'some word before then note: and some words after';
$word = "note:";
if (strpos($text, $word) !== false) {
echo "YAAAY {$word} found in position: " . strpos($text, $word);
}
输出
YAAAY note: found in position: 22
- 1 回答
- 0 关注
- 107 浏览
添加回答
举报
0/150
提交
取消