猿问

包含 em PHP 以返回 Regex

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


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


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


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

   return true

}

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


大话西游666
浏览 108回答 1
1回答

红糖糍粑

也许,我们并不需要一个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
随时随地看视频慕课网APP
我要回答