Jump to content

Filter non-case-sensitive


Twango

Recommended Posts

I'm making a filter, it's working good, let's pretend "Hello" is in the filter.It'll filter "Hello" but not "HeLlo"I can't convert the entire string to lowercase, because it's a profile... so i have no clue how to do this.

Link to comment
Share on other sites

Either convert what you're searching for and what you're searching in to the same case, or use a case-insensitive table. Those are basically the same thing, but you can either search in a case-insensitive manner using one of those techniques, or you can search for all possible cases, which is going to put a lot more work on the database. If you're not searching in a database, post the code you're using.

Link to comment
Share on other sites

my code retrieves profanity words from a txt, and profile from a dbCode:

$words = file('filter.txt', FILE_IGNORE_NEW_LINES);$re = implode('|', $words);$re = '/' . $re . '/';$prof = preg_replace($re, "*CENSORED*", $profd);

Link to comment
Share on other sites

Better add something else, too. If someone types the word 'assignment' you don't want to delete the first 3 letters. So try this:$re = '/\b' . $re . '\b/i';That makes sure you're filtering only whole words -- groups of characters separated by word boundaries, like a space, punctuation, or line break.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...