Best way to subtract one word set from another ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jeddiki
    Contributor
    • Jan 2009
    • 290

    Best way to subtract one word set from another ?

    Hi

    I have an array of common words:
    $common = array(a,the,abo ut,is,from,to,g o);

    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
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    Originally posted by jeddiki
    What would you recommend as the best way to do this ?
    thoroughly read PHP’s array functions descriptions. (hint: array_diff())

    Comment

    • jeddiki
      Contributor
      • Jan 2009
      • 290

      #3
      Thanks for the pointer :)

      Comment

      Working...