查找reg ex to null (空)字符串(如果它包含坏字)..
$string1 = "Ihatestackoverflow";
$string2 = "I HaTe sackoverflow";
$string3 = "1HaTestackoverflow";
$badword = "hate";
# result
# string1 = "";
# string2 = "";
# string3 = "";发布于 2010-06-05 03:57:26
$regex = '#^.*?(hate).*$#ims';
$str = preg_replace($regex, '', $str);要添加更多的“坏单词”,只需在()中添加它们:
$regex = '#^.*?(hate|anotherbadword|yetanother|etc).*$#ims';前导^和尾随$匹配完整字符串。I选项用于不区分大小写的匹配。M启用多行模式(以便^和$匹配整个字符串,而不是其中的一行)。S启用DOTALL (因此。也匹配换行符)。
你可以
https://stackoverflow.com/questions/2977313
复制相似问题