note 52340 added to function.strtok
| From: | soletan at toxa dot de | Date: | Thu, 28 Apr 2005 11:47:32 +0000 |
| Subject: | note 52340 added to function.strtok | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-88682@lists.php.net to get a copy of this message | ||
strtok's new behaviour isn't more correct than the old one.
Example: When parsing a string for a quoted-string (e.g. RFC822-header without wanting to install
mailparse from PECL!) then I walk char by char and whenever I encounter a double-quote I take strtok
to find the related closing double-quote in string quite easily ... this is done for improved
performance.
But what if there's an empty quoted-string ...
Another example is then having lines like
name="quoted-value"; second="another one";
I get the name using strtok with '=', then I check value to be quoted, which is true and
thus I take the method described before to get the quoted string. Then all what's left is
; second="another one";
now I advance and drop any whitespaces after current value assignment ... well users shouldn't
obey to never ever in life have no whitespaces before that damn semicolon for sure, and that's
why I drop that with strtok (using ';') again to get to the next optional assignment with
another
$s = strtok( '' )
I KNOW, there are ways to work around this using trim and the alikes. But that doesn't explain
why strtok is now working "correct" while it didn't do before ...
----
Manual Page -- http://www.php.net/manual/en/function.strtok.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+52340
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+52340&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+52340&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+52340&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+52340&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+52340&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+52340&report=yes
Search -- http://master.php.net/manage/user-notes.php