selecting words separated with comma with PHP -
a string contains words separated comma or space. using php, want select first 3 words have have minimum 4 characters(a-z, 0-9, -, _, #). example
$words = aa, one, ab%c, four, 5 six#
how select 'four', 'five', six# ? (probably each?)
dalen's suggestion run faster if have no strict requirements characters allowed. here regex solution since mention character requirements.
$words = 'aa, one, ab%c, four, 5 six#'; preg_match_all('/([a-z0-9_#-]{4,})/i', $words, $matches); print_r($matches);
and you'll have cut out want array after in dalen's answer.
Comments
Post a Comment