在 return 正则表达式中包含 em PHP

Contains em PHP in return Regex

我在搜索文本中的特定词时遇到困难。

我尝试使用 stripos 方法,但它抛出错误,因为文本 return 是一个对象:

$text = preg_replace("/note:/" ,'' , $text);

if(stripos($text, "note:") !== false){
   return true
}

如果字符串包含要在我的 if.

中使用的文本中的那个词,我需要它 return

也许,我们不需要 preg_replacestrpos 就足够了:

$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