ID:               31824
 Updated by:       [EMAIL PROTECTED]
 Reported By:      dpisarev at rogers dot com
-Status:           Open
+Status:           Feedback
 Bug Type:         Feature/Change Request
 Operating System: All
 PHP Version:      5.0.3
 New Comment:

Do you mean split() instead of strtok()?


Previous Comments:
------------------------------------------------------------------------

[2005-02-03 06:05:44] dpisarev at rogers dot com

Description:
------------
The existing string-tokenizing function (strtok) could be improved by
being made to take an additional parameter that would tell the function
to treat multiple adjacent delimiters as one for the purposes of
splitting up the string.

It appears that "preg_split" can accomplish the task but that would
involve concocting the right regular expressions -- which is a pain
that most people would prefer to avoid. Besides, the chatter on the
documentation threads is that messing with regular expressions slows
down execution.

Expected result:
----------------
Say, we have the string (omit the quotes):

"[EMAIL PROTECTED],   [EMAIL PROTECTED] [EMAIL PROTECTED];   [EMAIL PROTECTED]"

And suppose we want to parse it to extract the email addresses (imagine
we have a mailing list system where we add people's addresses in bulk
with all sorts of crazy formatting in between the addresses that we
don't have the time to neaten up).

So, the output of tokenizing the above string by the delimiters: ", ;"
should in my vision be an array of just FOUR elements, namely:

[EMAIL PROTECTED]
[EMAIL PROTECTED]
[EMAIL PROTECTED]
[EMAIL PROTECTED]

It is easy to see that one can find a lot of uses for this particular
tokenization algorithm.

Actual result:
--------------
The way things are now with strtok, I'd get an array of more than the
above-listed 4 elements. In addition to them I'd get a whole bunch of
empty elements in the array corresponding to all occurences of two
delimiters occuring side-by-side in the string to be tokenized.

Please feel free to concact me for any clarifications. In case the
improvement suggestion is integrated into PHP, credits will be
welcomed.


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=31824&edit=1

Reply via email to