$article="there are some of porn keywords, porn is not allowed print"; if($aticle without "porn") { echo "nothing"; } else { echo "$article"; } above that is my wish, but it's incorrect php syntax. could you teach me correct php syntax? thank you
<?php $article = "there are some of porn keywords, porn is not allowed print"; if(!preg_match('~\bporn\b~i', $article)) { //Article does not contain the word porn... } else { //Article contains the word porn... } ?> PHP:
Heres an example, to work with more than one word. <?php $article = "there are some of porn keywords, porn is not allowed print"; //array of words to disallow $words_to_disallow = array('porn', 'sex'); $escaped = array_map('preg_quote', $words_to_disallow); if(!preg_match('~\b('.implode("|", $escaped).')\b~i', $article)) { echo "Article seems clean..."; } else { echo "Article contains a disallowed word..."; } ?> PHP: