01-06-2010, 05:31 AM
|
#4 (permalink)
|
|
is cute and cuddly
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
|
Well that's probably because you're looking for an array in a string. Also, once you switch the arguments of in_array(), you're suddenly looking for each word of the original string inside of, you guessed it, the original string. At least with the example code you posted, but you may have done that from memory and mixed it up, I'm not sure.
The above method I suggested WILL work if done correctly, but it starts to get complicated once you start factoring in capture of words with punctuation attached, or if you want to find word fragments. Your best bet is to look into regular expressions - the basics are easy to pick up, and from there you can get as wild as you want.
For example, a simple search could be done ala;
php Code:
$string = "This is the test string."; $stopwords = array( 'bum', 'test' ); if ( preg_match( '~(' . implode( '|', $stopwords ) . ')~', $string ) ) { echo 'Found!'; }
|
|
|
|