note 111847 added to function.strtok
| From: | francesco dot montorsi at gmail dot com | Date: | Thu, 04 Apr 2013 10:33:22 +0000 |
| Subject: | note 111847 added to function.strtok | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-194334@lists.php.net to get a copy of this message | ||
A version of strtok() that returns an array containing all tokens found could be written as:
function strtok_all($string, $delim)
{
//echo "string: " . $string . " delim: " . $delim .
"<br/>";
$tok = strtok($string, $delim);
$arr = array();
//echo "tok: " . $tok;
while ($tok !== false)
{
$arr[] = $tok;
$tok = strtok($delim);
}
return $arr;
}
note that this works similarly to explode() but, unlike explode(), ANY of the character provided as
$delim will be used to tokenize the string!
----
Server IP: 69.147.83.199
Probable Submitter: 217.133.33.244
----
Manual Page -- http://php.net/manual/en/function.strtok.php
Edit -- https://master.php.net/note/edit/111847
Del: integrated -- https://master.php.net/note/delete/111847/integrated
Del: useless -- https://master.php.net/note/delete/111847/useless
Del: bad code -- https://master.php.net/note/delete/111847/bad+code
Del: spam -- https://master.php.net/note/delete/111847/spam
Del: non-english -- https://master.php.net/note/delete/111847/non-english
Del: in docs -- https://master.php.net/note/delete/111847/in+docs
Del: other reasons-- https://master.php.net/note/delete/111847
Reject -- https://master.php.net/note/reject/111847
Search -- https://master.php.net/manage/user-notes.php