Last active
April 25, 2019 22:17
-
-
Save calexandrepcjr/5c07bdada368e1cb23c689a76dd30534 to your computer and use it in GitHub Desktop.
Flag bad words by a bad words list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function flagWords($text, $badwords) | |
{ | |
$badword = reset($badwords); | |
while ($badword) { | |
$text = preg_replace( | |
'/('. preg_quote($badword) .')/i', | |
'<span style="color:red;">$1</span>', | |
$text | |
); | |
$badword = next($badwords); | |
} | |
$text = preg_replace( | |
'/\d+/i', | |
'<span style="color:red;">$0</span>', | |
$text | |
); | |
return $text; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment