我在搜索文本中的特定單詞時遇到困難。我嘗試使用該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 關注
- 131 瀏覽
添加回答
舉報
0/150
提交
取消