php - Bad word list in forum (preg match) only count
in my forum I would like to check a string (post text and post title) for bad words. The words should NOT be replaced. When the FIRST bad word is count, do something. I dont want to work with foreach because foreach will do the echo for every bad word found. I need only a count. If count a bad word then > go
I have already
$str = $row['post_text'].$topic_data['topic_title'];
$bad = array('badword','badword2');
if (preg_match($str,$bad)){
echo 'true';
}else{
echo 'false';
}
this did not work..thank for help
Answer
Solution:
Use for each on your bad word array and check it as a stristr() of the $str, on success exit the for each with $badword = true, then you can post a response if $badword == true after the loop.