Preg replace - reg ex needed
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 = "";
# strin开发者_开发知识库g3 = "";
$regex = '#^.*?(hate).*$#ims';
$str = preg_replace($regex, '', $str);
To add more "bad words", just add them in the ():
$regex = '#^.*?(hate|anotherbadword|yetanother|etc).*$#ims';
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
精彩评论