how to filter porn article?

Discussion in 'PHP' started by Adulu, Apr 20, 2010.

  1. #1
    $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
     
    Adulu, Apr 20, 2010 IP
  2. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #2
    <?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:
     
    danx10, Apr 20, 2010 IP
  3. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #3
    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:
     
    danx10, Apr 20, 2010 IP
  4. Adulu

    Adulu Peon

    Messages:
    2,791
    Likes Received:
    43
    Best Answers:
    0
    Trophy Points:
    0
    #4
    it's works.
    Thank you so much.:)
     
    Adulu, Apr 20, 2010 IP