 <p>Try to put it with explode into an array and count the values with array_count_values. </p> <pre><code>&lt;?php $text = "whatever"; $text_array = explode( ' ', $text); $double_words = array(); for($c = 1; $c &lt; count($text_array); $c++) { $double_words[] = $text_array[$c -1] . ' ' . $text_array[$c]; } $result = array_count_values($double_words); ?&gt; </code></pre> <p>I updated it now to two word version. Does this work for you?</p> <pre><code>array(9) { ["I am"]=&gt; int(1) ["am purchasing"]=&gt; int(1) ["purchasing a"]=&gt; int(2) ["a wallet"]=&gt; int(2) ["wallet a"]=&gt; int(1) ["wallet for"]=&gt; int(1) ["for 20$"]=&gt; int(1) ["20$ purchasing"]=&gt; int(1) ["a bag"]=&gt; int(1) } </code></pre>