我在搜索文本中的特定單詞時(shí)遇到困難。我嘗試使用該stripos方法,但它拋出一個(gè)錯(cuò)誤,因?yàn)槲谋痉祷氐氖且粋€(gè)對(duì)象:$text = preg_replace("/note:/" ,'' , $text);if(stripos($text, "note:") !== false){ return true}如果字符串在文本中包含要在我的if.
1 回答

紅糖糍粑
TA貢獻(xiàn)1815條經(jīng)驗(yàn) 獲得超6個(gè)贊
也許,我們并不需要一個(gè)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 關(guān)注
- 130 瀏覽
添加回答
舉報(bào)
0/150
提交
取消