Skip to content

PhilEcapp/badwords

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

Remove bad words (swearwords) in PHP

badwords.php Code

This is the PHP code file.
function censor($string)
{
if ($string)
{
$badwords = file_get_contents("badwords.txt");
$badwords = explode(",", $badwords);
$replacewith = array();
$index = 0;
foreach ($badwords as $value) {
$lengthOfStars = strlen($badwords[$index]) - 2;
$replacewith[$index] = substr($badwords[$index], 0, 1).str_repeat("*", $lengthOfStars).substr($badwords[$index], -1);
$index++;
}
$newstring = str_ireplace($badwords, $replacewith, $string);
return $newstring;
}
}

echo censor("Some really bad swear words to remove");

?>

badwords.txt File

bad,words

About

Remove bad words (swearwords) in PHP

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages