0

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

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by rajeesh_rsn
0

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?

0

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

Once again thanks a lot

Regards
Rajeesh

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.