Jump to content

Recommended Posts

So what I need is a function that filters out words, in a text file (new word on each line) and replaces all but the first letter with starts, like if i where to say asswipe, i need to to replace it with a****** the thing is, I also need it to not be case sensitive, and look for repetitive letters, say someone said assswipe.. that second part isn't required - it would just be nice. All i have so far is

 

function LangFilter($string) {
$badwords=fopen("./langfilter.txt","r");
for ($i=0;$i < count($badwords);$i++){ 
$string = str_replace($badwords[$i],str_repeat("*",strlen($badwords[$i])),$string); 
} 
return $string; 
} 

 

But it doesn't work. The reason im not saying its a cuss word filter, is there are some other things I would need it to filter, but ill do those my self. I looked on a few other topics, but none of those had what I needed... Any help? Thanks!

Link to comment
https://forums.phpfreaks.com/topic/273649-word-filter/
Share on other sites

Given the word "asswipe" you can do a replace with regular expressions.

$input = "Bob is such an aasssswwiipee";

$word = "asswipe";

$matchword = implode("+", array_map("preg_quote", str_split($word))) . "+"; // a+s+s+w+i+p+e+
$output = preg_replace_callback('/\b' . $matchword . '\b/i', function($matches) {
return $matches[0][0] . (strlen($matches[0]) > 1 ? str_repeat("*", strlen($matches[0]) - 1) : "");
}, $input);

Link to comment
https://forums.phpfreaks.com/topic/273649-word-filter/#findComment-1408283
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.