Preg 替换 - 需要 reg ex
寻找一个 reg ex 来将字符串清空(如果字符串中包含坏词的话)。
$string1 = "Ihatestackoverflow";
$string2 = "I HaTe sackoverflow";
$string3 = "1HaTestackoverflow";
$badword = "hate";
# result
# string1 = "";
# string2 = "";
# string3 = "";
Looking for a reg ex to null (empty) the string if it any contains the bad word..
$string1 = "Ihatestackoverflow";
$string2 = "I HaTe sackoverflow";
$string3 = "1HaTestackoverflow";
$badword = "hate";
# result
# string1 = "";
# string2 = "";
# string3 = "";
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要添加更多“坏词”,只需将它们添加到 () 中:
前导 ^ 和尾随 $ 匹配完整字符串。 i 选项用于不区分大小写的匹配。 m 启用多行模式(以便 ^ 和 $ 匹配整个字符串,而不是其中的单行)。 s 启用 DOTALL(因此 . 也匹配换行符)。
你可以
To add more "bad words", just add them in the ():
The leading ^ and trailing $ match the full string. The i option is for case insensitive matching. The m enables multi-line mode (so that ^ and $ match the whole string, as opposed to a single line in it). The s enables DOTALL (so the . matches new line characters as well).
You could