note 116490 added to function.preg-split
| From: | markac | Date: | Sun, 11 Jan 2015 16:08:26 +0000 |
| Subject: | note 116490 added to function.preg-split | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-201408@lists.php.net to get a copy of this message | ||
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)
----
Server IP: 72.52.91.14
Probable Submitter: 91.192.89.35
----
Manual Page -- http://php.net/manual/en/function.preg-split.php
Edit -- https://master.php.net/note/edit/116490
Del: integrated -- https://master.php.net/note/delete/116490/integrated
Del: useless -- https://master.php.net/note/delete/116490/useless
Del: bad code -- https://master.php.net/note/delete/116490/bad+code
Del: spam -- https://master.php.net/note/delete/116490/spam
Del: non-english -- https://master.php.net/note/delete/116490/non-english
Del: in docs -- https://master.php.net/note/delete/116490/in+docs
Del: other reasons-- https://master.php.net/note/delete/116490
Reject -- https://master.php.net/note/reject/116490
Search -- https://master.php.net/manage/user-notes.php