note 112690 deleted from function.strtok by googleguy
| From: | googleguy@php.net | Date: | Sat, 13 Jul 2013 12:20:26 +0000 |
| Subject: | note 112690 deleted from function.strtok by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-195602@lists.php.net to get a copy of this message | ||
Note Submitter: mail at markuszeller dot com
----
This function should be handled with care if you want to use the tokenizer for multiple strings at
once!
It looks like there's a PHP internal global and single unique position storage. See code
example below.
$s1 = $s2 = "1 2 3 4 5 6";
$tok1 = strtok($s1, " ");
echo "$tok1\n";
$tok1 = strtok(" ");
echo "$tok1\n";
$tok1 = strtok(" ");
echo "$tok1\n";
$tok1 = strtok(" ");
// 1
// 2
// 3
$tok2 = strtok($s2, " ");
echo "$tok2\n";
$tok2 = strtok(" ");
echo "$tok2\n";
$tok2 = strtok(" ");
echo "$tok2\n";
// 1
// 2
// 3
$tok1 = strtok(" ");
echo "$tok1\n";
$tok2 = strtok(" ");
echo "$tok2\n";
// 4
// 5
But I would have expected to have output $tok1 to be 4 AND $tok2 to be 4.