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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.