Check For Bad Words Using PHP

Here’s a PHP function I like to use to check a string if it contains any of the words from an array. I had a situation where I didn’t want to load any client or Adsense ads on pages that contained topics that weren’t approved.

$badwords = array('boob', 'butt', 'dummy', 'dummyhead');
function contains($str, array $arr)
foreach($arr as $a) {
if (stripos($str,$a) !== false) return true;
return false;
if (contains($titlelower, $badwords) !== FALSE) {
$titlebadwordcheck = '1';