<?php
function censor( $str )
{
/*
load bad words, separated by line break, eg:
<a href="https://www.createaforum.com/censorinfo.php?subdomain=deptnav" target="_blank">****</a>
<a href="https://www.createaforum.com/censorinfo.php?subdomain=deptnav" target="_blank">****</a>
<a href="https://www.createaforum.com/censorinfo.php?subdomain=deptnav" target="_blank">****</a>
*/
$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 <a href="https://www.createaforum.com/censorinfo.php?subdomain=deptnav" target="_blank">****</a> <a href="https://www.createaforum.com/censorinfo.php?subdomain=deptnav" target="_blank">****</a>!";
echo $string; //Hello you <a href="https://www.createaforum.com/censorinfo.php?subdomain=deptnav" target="_blank">****</a> <a href="https://www.createaforum.com/censorinfo.php?subdomain=deptnav" target="_blank">****</a>!
echo censor( $string ); //Hello you ****ing *****!
?>
/*
load bad words, separated by line break, eg:
****
****
****
*/
$bad_words = file( "bad_words.txt" );
If you'd like, you can edit which bad words you'd like to censor ^. As you progress down the code, you'll come across:
$bad_word = trim( $bad_word );
if ( preg_match( "/" . $bad_word . "/i", $str ) )
{
$new_word = '';
for ( $i = 1; $i <= strlen( $bad_word ); $i++ )
{
$new_word .= '*';
Feel free to alter the filter from '*' to anything such as 'bobba' or '%@!*&amp;' etc.