Skip to content

Instantly share code, notes, and snippets.

@calexandrepcjr
Last active April 25, 2019 22:17
Show Gist options
  • Save calexandrepcjr/5c07bdada368e1cb23c689a76dd30534 to your computer and use it in GitHub Desktop.
Save calexandrepcjr/5c07bdada368e1cb23c689a76dd30534 to your computer and use it in GitHub Desktop.
Flag bad words by a bad words list
<?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