I wasn't sure whether this was a tutorial or a free script, but I can't be bothered to explain the code properly so I'm just going to dump the script - there for it is a free script.
So anyway, I coded this for my college website I am currently working on and thought people may be interested in it.
So anyway, I coded this for my college website I am currently working on and thought people may be interested in it.
PHP:
<?php
function censor( $str )
{
/*
load bad words, separated by line break, eg:
shit
fuck
bitch
*/
$bad_words = file( "bad_words.txt" );
foreach ( $bad_words as $bad_word )
{
$bad_word = trim( $bad_word );
if ( preg_match( "/" . $bad_word . "/i", $str ) )
{
$new_word = '';
for ( $i = 1; $i <= strlen( $bad_word ); $i++ )
{
$new_word .= '*';
}
$str = eregi_replace( $bad_word, $new_word, trim( $str ) );
$new_word = '';
}
}
return $str;
}
$string = "Hello you fucking bitch!";
echo $string; //Hello you fucking bitch!
echo censor( $string ); //Hello you ****ing *****!
?>