为了账号安全,请及时绑定邮箱和手机立即绑定

包含 em PHP 以返回 Regex

包含 em PHP 以返回 Regex

PHP
大话西游666 2021-08-28 16:24:58
我在搜索文本中的特定单词时遇到困难。我尝试使用该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


查看完整回答
反对 回复 2021-08-28
  • 1 回答
  • 0 关注
  • 107 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信