PHP Get first 3 words from string
<p>The following code splits a string and selects all of the alphanumeric words containing minimum 3 letters. However instead of getting all the words from the string, I want to get only first 3 valid words, but the problem is with the loop. How can I stop the loop as soon as 3 valid words are found from the string.</p>

<p>PS. If there is an alternative approach to the same thing, please suggest.
Thanks.</p>

<pre><code>$string = "test test TEST test- -test _test blsdk.bldf,las";

$arr = preg_split('/[,\ \.;]/', $string);
$keywords = array_unique($arr);
foreach ($keywords as $keyword){
            if ((preg_match("/^[a-z0-9]/", $keyword) ) &amp;&amp; (strlen($keyword) &gt; 3)){
                    echo $keyword;
                    echo "&lt;br /&gt;";
            }
        }
</code></pre>
