Jump to content

Bad words filter help


cordoprod

Recommended Posts

Hi.

 

I need some help with a bad word filter.

 

I have a variable to store the words in, seperated by comma.

Like this:

$badwords = "bad1,bad2,bad3,bad4";

 

Then I can use the explode(",", $badwords);

But, I now i don't know what to do.

 

I want to cut the away all letters but one, and replacing those letters with ** and keep the length of the word.

 

Like bad1 would be like this: b***

 

Anybody here that can help me?

Link to comment
https://forums.phpfreaks.com/topic/97626-bad-words-filter-help/
Share on other sites

Something like:

<?php
$badwords = array("bad1","bad2","bad3");

$post = "this is a bad1 word.";

foreach ($badwords as $key => $word)
{
$len = strlen($word) -1;
while ($len > 0)
	{
	$asterix .= "*";
	$len--;
	}
$post = str_ireplace($word,$word{0} . $asterix,$post);
}

echo $post;
?>

 

Untested.

Link to comment
https://forums.phpfreaks.com/topic/97626-bad-words-filter-help/#findComment-499516
Share on other sites

same concept...a little shorter:

 

<?php
$badwords = array("bad1","bad2","bad3");
$post = "this is a bad1 word.";
foreach ($badwords as $key => $word)
  $post = str_ireplace($word,$word{0}.str_repeat('*',strlen($word)-1),$post);
echo $post;
?>

ooo I didn't know there was a str_repeat function. Thanks.

Link to comment
https://forums.phpfreaks.com/topic/97626-bad-words-filter-help/#findComment-499529
Share on other sites

When i use the code i get this error:

 

Fatal error: Allowed memory size of 16777216 bytes exhausted (tried to allocate 16252905 bytes) in /customers/cordoproduction.com/cordoproduction.com/httpd.www/php/collection/Guestbook/guestbook.php on line 383

Which code are you talking about? The code in my box works, I made a change to it. You must have used the code a second before I corrected it.
Link to comment
https://forums.phpfreaks.com/topic/97626-bad-words-filter-help/#findComment-499536
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.