Connecting Tech Pros Worldwide Forums | Help | Site Map

Best way to subtract one word set from another ?

Familiar Sight
 
Join Date: Jan 2009
Posts: 165
#1: 3 Weeks Ago
Hi

I have an array of common words:
$common = array(a,the,about,is,from,to,go);

and a string that is a long paragraph of words.
$words
(It could of course be turned into and array as well.)

What I want to do is to remove the common words from my
string and I am not sure if I should do this with a regex, or a foreach loop
or if there is a particular array function that would suit the purpose.

I have looked through the array function list but can not see anything
specifically for this. I could perhaps use the change $words into an array
and use the in_array($words)

What would you recommend as the best way to do this ?

Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,660
#2: 3 Weeks Ago

re: Best way to subtract one word set from another ?


Quote:

Originally Posted by jeddiki View Post

What would you recommend as the best way to do this ?

thoroughly read PHP’s array functions descriptions. (hint: array_diff())
Familiar Sight
 
Join Date: Jan 2009
Posts: 165
#3: 3 Weeks Ago

re: Best way to subtract one word set from another ?


Thanks for the pointer :)
Reply