Hai,
I had developed a self forum ( not third party ) for my web site. Working fine... But now I need to filter some words while submitting the form. Ie If I need to filter the word "duck" in forum then if an user type "duck" in any of the text box/area then I need to change that into "d**k" on form submitting.

Please give me a little advice to solve this problem...

Thanks in advance
Rajeesh

Hey.

Consider this:

<?php
/**
 * Obfuscates a word by replacing all but the first and the last letters with *
 * @param string $word The unscrabled word.
 * @return string
 */
function obfuscateWord($word)
{
    $first = $word[0];
    $last = $word[strlen($word)-1];
    $middle = "";
    for($i = 0; $i < strlen($word)-2; $i++)
    {
        $middle .= "*";
    }
    return $first . $middle . $last;
}

// A list of banned words
$wordList = array('duck', 'fick');

// Compile the regular expression that searches for the words in the list.
$regexp = '/(' . implode('|', $wordList) . ')/ie';

// The "callback" for the regular exrepssion matches.
// This calls the obfuscateWord function, passing the matches word and replacing it
// with the scrambled word.
$replace = 'obfuscateWord("$1");';

// Example text to use
$text = "There is a duck on the fick!";

// Do the actual replace.
$text = preg_replace($regexp, $replace, $text);

echo $text;
?>

That should work, right?

Thanks for your kind help... let me check ...

Once again thanks a lot

Regards
Rajeesh

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.