Split string into words.
<?php
$string = 'This - is a, very dirty "string" :-)';
// split into words
$wordlist = preg_split('/\W/', $string, 0, PREG_SPLIT_NO_EMPTY);
// returns only words that have minimum 2 chars
$wordlist = array_filter($wordlist, function($val) {
return strlen($val) >= 2;
});
// print
var_dump($wordlist);
?>
Result:
array (size=5)
0 => string 'This' (length=4)
1 => string 'is' (length=2)
3 => string 'very' (length=4)
4 => string 'dirty' (length=5)
5 => string 'string' (length=6)