php - Bad word list in forum (preg match) only count

543

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

134

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.

People are also looking for solutions to the problem: php - Category not show in Magento admin panel at the time of product update

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.