need help for wordfilter and replace

Discussion in 'PHP' started by aadi92s, Mar 20, 2010.

  1. #1
    hi ,
    i want a function ,
    Please help me,,,,,,,,
    when user post reply
    
    $reply="Hello this is testing message"; //user reply text
    $res=mysql_query("select * from wordfilter");
    while ($row=mysql_fetch_array($res)){
    $word=$row['words']; // delete, insert, drop , etc..........
    } 
    
    PHP:
    if $reply any word match to $word then he replace it
    first word and last word same and middle word replace to *****

    forexemple he found sexy and hi also in my database (in $word) then he replace it s**y
    if hi found one word then replace one
    if found two word then two .....there ....... four ................................................................................
     
    aadi92s, Mar 20, 2010 IP
  2. Alex Roxon

    Alex Roxon Active Member

    Messages:
    424
    Likes Received:
    11
    Best Answers:
    7
    Trophy Points:
    80
    #2
    function Replace( $Word )
    {
    	$Replace = substr( $Word, 0, 1 );
    	for( $x = 0; $x <= strlen( $Word ) - 2; $x++ )
    		$Replace .= "*";
    	$Replace .= substr( $Word, -1 );
    	return $Replace;
    }
    
    $reply = "Hello this is a sexy testing vagina message";
    
    $res = mysql_query("select * from wordfilter");
    while( $row = mysql_fetch_array( $res ) )
    {
    	$Word = $row['words'];
    	if( stripos( $reply, $Word ) )
    		$reply = str_ireplace( $Word, Replace( $Word ), $reply );
    }
    
    PHP:
    Should work for you. Then again, it's 2am and untested.
     
    Alex Roxon, Mar 20, 2010 IP
  3. aadi92s

    aadi92s Peon

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Wao ,
    thanx bro its working and helpful for me,
    thanx again :)
     
    aadi92s, Mar 21, 2010 IP