I have an array of stop words that i would like removed from a string. But in every case the words like 'in' are being removed from valid words like climbing leaving climb g in the resulting string.
I was thinking if I could have two arrays. One array of the stop words and one array of the exploded string. Is there a quick way to use the array of stop words to compare against the array of the exploded string, thus removing all stop words from the exploded string array...
$stopwords = array( 'foo', 'bar');
$string = "foo bar Foobar";
$newArray = explode(" ", $string)
I would like the resulting $string = "Foobar"?
thanks in advance,
Marv
array_diff is your friend to eliminate the words you don't like too see:
$string = implode(" ", array_diff(explode(" ", $string), $stopwords));
You can use array_diff, it will return you the difference between first and second array. For conversion to string, you must make sure you have only 1 last element (with count, for instance)