Forum Moderators: coopster
A good starting point is 'word stemming algorythm' (or some variation thereof) in your favorite SE.
I also recommend looking into preg_split, array_count_values, strlen, array_walk and preg_replace...
Justin
preg_replace - will allow you to replace words in a string - powerful takes more time to run
preg_match - will allow you to check for words in a string - powerful takes more time to run
stristr - will allow you to check for words in a string - stristr is case insensitive, strstr is not. - faster, than preg, but no regex options
stripos - will allow you to check for a word in a string - stripos is case insensitive, strpos is not. - faster, than preg, but no regex options
in_array - will allow you to check and see if a word is in an array - the least powerful solution & case sensitive, so not recommended.
Either:
$changetowords = explode(" ", $string); (recommended, faster) OR
$changetowords = preg_split("/[\s,]+/", $string);
Will allow you to break the string as you requested.
There are some other ways, but these are the most used.
Wish I could be more help, but am not sure other than finding a word how you would like to handle things from there. How many words or variations of words you are looking for will also impact which one you should use. - these should give you a start.
For a single word I would probably use stristr:
$string = 'This is a string with a badword.';
if(stristr($string, 'badword')) { echo 'found a bad word'; }
Justin