1 回答

TA貢獻(xiàn)1906條經(jīng)驗(yàn) 獲得超3個(gè)贊
嘗試使用值中的 \b 字邊界以及 /i 不敏感修飾符和 preg_replace:
$search = "My name is Christina and this is another example, my friends are Lola and Monica and Monic and Chris. As lowercase: lola, christina, monic, monica, chris.";
$AllNames = ["/Lola/i", "/Chris\b/i", "/Monic\b/i"];
$search = preg_replace($AllNames, '****', $search);
echo $search;
輸出:
My name is Christina and this is another example, my friends are **** and Monica and **** and ****. As lowercase: ****, christina, ****, monica, ****.
請(qǐng)注意,我沒有在 Lola 中使用單詞邊界,但如果需要,可以輕松添加。
- 1 回答
- 0 關(guān)注
- 155 瀏覽
添加回答
舉報(bào)