Word filter

Discussion in 'PHP' started by SharingEngines, Feb 27, 2011.

  1. #1
    Hi,

    I need a Filtering words before inserting into db

    	$select=mysql_query("SELECT * FROM sh WHERE tags='$displaysearch' LIMIT 1") or die(mysql_error()); 
    
        if( mysql_num_rows($select) ){ 
        mysql_query("UPDATE sh SET count=count+1 WHERE tags='$displaysearch'") or die(mysql_error()); 
        }else{ 
        mysql_query("INSERT INTO sh SET tags='$displaysearch'") or die(mysql_error()); 
    	
    } 
    Code (markup):
    Using something like this:
    When I write the word "sex" is replaced by ","

    $placeholders = array('http', '//', ':', 'sex');
    $replacement = array('', '', '', '');
    Code (markup):
    The problem is I don´t know how to resolve this.

    Could you can help me?

    Thank you very much.
     
    Last edited: Feb 27, 2011
    SharingEngines, Feb 27, 2011 IP
  2. mmatthew

    mmatthew Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    
    $placeholders = array('http', '//', ':', 'sex');
    $replacement = ''; // you don't have to pass an array with empty strings
    $censored = str_replace($placeholders, $replacement, $displaysearch);
    
    PHP:
    The code above will replace all strings from $placeholders with $replacement value(empy string in this case).
     
    mmatthew, Mar 13, 2011 IP