Forum Moderators: coopster
Check out the info at PHP.net
-ereg function [php.net]
-eregi function [php.net] (not case sensitive)
[edited by: GamingLoft at 10:28 pm (utc) on Feb. 5, 2008]
Here is related topic [webmasterworld.com...]
Here's my code...
-----------------------
Form :
<form method="POST" action="$_SERVER[PHP_SELF]">
Your name: <input type="text" name="username">
<input type="submit" value="submit">
</form>
---------------------
Censorship:
$censor_word = 'fuxxk'
$test = strpos($username, $censor_word);
if ($test === true) {
echo "Don't call yourslef '$censor_word'. Use a proper name";
}
-----------------------
It seems fairly inefficient with this method. I'll try to use array to include more censored words (use foreach function?) .
I'd like to follow Duskrider's suggestion to use a text file to include dozens of bad words in one file, but have no idea how to do it yet. I appreciate any hints for this.
Thanks!
// Read the contents of 'badwords.txt' into an array
// trimming the newline characters as we do so.
$file = array_map('rtrim',file('badwords.txt'));
// Now just like Dreamcatcher said:
$string = str_replace($file,'*',$string);
That should look through your string and replace anything that looks like a line from the textfile with asterisks(*). If you wanted to replace it with something else, you could do that. If you don't care about case (you want to block Badword and badword and BaDWoRd but don't want to list each one in your text file individually) you should use str_ireplace instead.