Retaining certain phrases in a string
<p>The code below returns a list of words most frequently-occurring in the string <code>$commentstring</code>, cleaned of punctuation and numbers.  It works fantastic.</p>

<p>However, colloquial phrases and brand names are broken up into individual words.  I would like to combine them.</p>

<p>So, if the word "french" appears immediately before "fries" I would like to keep them combined as the word "french fries."  I would like to come up with a list of phrases like this such as "chocolate chip," "coca cola," "old school", etc.  How could I do this?</p>

<pre><code>$commentstring = str_replace(array('/', '*', ')', '(', '!', '.', ',', ':'), '', $commentstring);

    $words = explode(" ", $commentstring);


    $result = array();

    arsort($words);







foreach($words as $word) {

    if(!is_numeric($word)){
        $result[$word]++;
        arsort($result);
    }

}




    echo "&lt;table&gt;";


        $blacklist = array($submission, 'DESPITE', 'FARE', 'DECENT', 'AMAZING', 'WOULD', 'DISLIKE', 'HATE', 'OKAY', 'JUST', 'NOTHING', 'CURRENTLY', 'BASICALLY', 'BIT', 'COME', 'WANT', 'TOO', 'HERE', 'EATING', 'EAT', 'WAS', 'TRIED', 'TRY', 'MAKES', 'HAS', 'EVEN', 'THINK', 'BETTER', 'YET', 'MORE', 'LOVE', 'WHILE', 'WHERE', 'WRONG', 'FIND', 'EVER', 'RIGHT', 'BEST', 'HAVE', 'WE', 'WAY', 'GREAT', 'NICE', 'HOW', 'RESTAURANTS', 'RESTAURANT', 'EXCELLENT', 'FORGET', 'THEY', 'REALLY', 'MISS', 'VERY', 'LOOKING', 'YOU\'LL', 'CAN\'T', 'WON\'T', 'PLACE', 'ABOUT', 'FOR', 'MOST', 'GOOD', 'CAN', 'GET', 'THING', 'DON\'T', 'BY', 'YOUR', 'BE', 'YOU', 'BRING', 'THAT\'S', 'LITTLE', 'OTHER', 'MANAGES', 'ATE', 'ATE', 'EAT', 'SO', 'SOMEHOW', 'MAKE', 'ALL', 'UP', 'THEM', 'AS', 'THEM', 'YOU\'RE', 'WILL', 'ONLY', 'IF', 'GO', 'DO', 'I\'VE', 'HAD', 'TO', 'SOME', 'FOOD', 'THIS','DOES', 'NOT', 'IT.', 'IT,', 'SEEM', 'END', 'THERE\'S', 'WHETHER', 'DOUBT', 'WHAT', 'WHICH', 'RECOMMEND', 'THE', 'IS', 'A', 'IT\'S', 'OUT', 'JAN', 'IT', 'IT', 'IT', 'LIKE', 'THAN', 'WITH', 'SEEMS', 'WHICH', 'THAT', 'SAY', 'AT', 'ON', 'AN', 'BUT', 'APART', 'STILL', 'ARE', 'OR', 'TEST', 'IN', 'IT', 'AND', 'SET', 'TO', 'NO', 'OF', '', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'AA', 'BB', 'CC', 'DD', 'EE', 'FF', 'GG', 'HH', 'II', 'JJ', 'KK', 'LL', 'MM', 'NN', 'OO', 'PP', 'QQ', 'RR', 'SS', 'TT', 'UU', 'VV', 'WW', 'XX', 'YY', 'ZZ');


foreach($result as $word =&gt; $count1)
{
    if (in_array($word, $blacklist)) continue;


    echo '&lt;tr&gt;';    
    echo '&lt;td&gt;';
    echo "$word";
    echo '&lt;/td&gt;';

    echo '&lt;td&gt;';
    echo "$count1 ";
    echo '&lt;/td&gt;';

    echo '&lt;/tr&gt;';

    }

    echo "&lt;/table&gt;";
</code></pre>
