Twango Posted April 5, 2011 Share Posted April 5, 2011 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 More sharing options...
justsomeguy Posted April 5, 2011 Share Posted April 5, 2011 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 More sharing options...
Twango Posted April 5, 2011 Author Share Posted April 5, 2011 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 More sharing options...
jeffman Posted April 6, 2011 Share Posted April 6, 2011 Are you saying you want to match words no matter what the case is? If that's it, add the i modifier to your regex:$re = '/' . $re . '/i'; Link to comment Share on other sites More sharing options...
Twango Posted April 6, 2011 Author Share Posted April 6, 2011 Cool! Thanks it works... Link to comment Share on other sites More sharing options...
jeffman Posted April 6, 2011 Share Posted April 6, 2011 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.