Search engine

Question by Scott:
How to make a blacklist of swear words in my game.?

I would like to make a script in php that stops anyone writing swear words or foreign URLS (mainly other game sites) on my game, is there a script already made to do this because i dont know where to begin making this script.
Any help would be much appreciated


——————————————

Answer by Aerivium
Whenever someone is able to send text that you wan’t to filter out the blacklisted items, you need to put it into a method which takes in a string and returns the filtered strign

Example:

function filter($ cleanString){
//Filter here
return $ filteredString;
}

Where it states “//Filter here” you need to remove the words you do not want

http://uk3.php.net/manual/en/function.str-replace.php this url will tell you how you can replace a word with what you want

I would recommend putting this filter method inside a separate php file such as filter.php which you then include wherever it is needed.

Now for the words, you can either create an array inside the filter.php class of all the words to be removed, you could also make an array of replacements for the words, or just statically set the same replacement for each word. OR you could store this information in a table inside a mysql database.

For urls its a bit harder as you need to look for url patterns

a easy way it could be done is by looking for http:// and www. and removing everything until the next space and looking for .com .co.uk .org and .net (or others) and removing everything Before upto the next space

This example might be useful for finding these occurences

http://www.phpro.org/examples/Find-Position-Of-Nth-Occurrence-Of-String.html

——————————————
Know better? Leave your own answer in the comments!