Jump to content

[SOLVED] PHP Bad word filter


DeanWhitehouse

Recommended Posts

I have made this bad word filter, and i want it to be able to find the bad word whether it is in lowercase (e.g. f*ck), uppercase (e.g. F*CK) or a mixture (e.g. F*cK)

I want to do this without changing the comment (it's a comment system) to lowercase or uppercase.

 

This is how i tried it

<?php
$bad = array('removed for younger/more sensitive readers. In summary it contained a list of banned words, with variations. Some in mixed cases');
if(isset($_POST['Go!']))
{
$name = make_safe($_POST['name']);
$message = make_safe($_POST['msg']);

foreach($bad as $low)
{
	$bader[] = strtolower($low);
}

foreach($bad as $high)
{
	$worse[] = strtoupper($high);
}

foreach($bad as $first)
{
	$omg[] = ucfirst($first);
}

$name = str_replace($bader,"*****",$name);
$name = str_replace($worse,"*****",$name);
$name = str_replace($omg,"*****",$name);
$name = str_replace($bad,"*****",$name);

$message = str_replace($bad,"*****",$message);
$message = str_replace($bader,"*****",$message);
$message = str_replace($worse,"*****",$message);
$message = str_replace($omg,"*****",$message);
echo $name."<br>".$message;
}
		?>
		<form action="" method="post">
		Name <input type="text" name="name" id="nme" maxlength="20" size="15" value="<?php if(isset($_POST['nme'])){echo $_POST['nme'];}?>" ><br>
		Message
			<p><textarea rows="5" cols="53" name="msg" id="txt"><?php if(isset($_POST['msg'])){echo $_POST['msg'];}?></textarea></p>
			<p class="links"><input type="submit" value="Submit" name="Go!" id="x" >     <input type="reset" value="Reset" name="reset" id="x"></p>
		</form>	

Now as you can tell this is not the most efficient way of doing it, what would you advise?

EDIT: This is only a small part of the code.

Link to comment
https://forums.phpfreaks.com/topic/132622-solved-php-bad-word-filter/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.