From:             dpisarev at rogers dot com
Operating system: All
PHP version:      5.0.3
PHP Bug Type:     Feature/Change Request
Bug description:  strtok() improvement suggestion

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 bug report at http://bugs.php.net/?id=31824&edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=31824&r=trysnapshot4
Try a CVS snapshot (php5.0): 
http://bugs.php.net/fix.php?id=31824&r=trysnapshot50
Try a CVS snapshot (php5.1): 
http://bugs.php.net/fix.php?id=31824&r=trysnapshot51
Fixed in CVS:                http://bugs.php.net/fix.php?id=31824&r=fixedcvs
Fixed in release:            http://bugs.php.net/fix.php?id=31824&r=alreadyfixed
Need backtrace:              http://bugs.php.net/fix.php?id=31824&r=needtrace
Need Reproduce Script:       http://bugs.php.net/fix.php?id=31824&r=needscript
Try newer version:           http://bugs.php.net/fix.php?id=31824&r=oldversion
Not developer issue:         http://bugs.php.net/fix.php?id=31824&r=support
Expected behavior:           http://bugs.php.net/fix.php?id=31824&r=notwrong
Not enough info:             
http://bugs.php.net/fix.php?id=31824&r=notenoughinfo
Submitted twice:             
http://bugs.php.net/fix.php?id=31824&r=submittedtwice
register_globals:            http://bugs.php.net/fix.php?id=31824&r=globals
PHP 3 support discontinued:  http://bugs.php.net/fix.php?id=31824&r=php3
Daylight Savings:            http://bugs.php.net/fix.php?id=31824&r=dst
IIS Stability:               http://bugs.php.net/fix.php?id=31824&r=isapi
Install GNU Sed:             http://bugs.php.net/fix.php?id=31824&r=gnused
Floating point limitations:  http://bugs.php.net/fix.php?id=31824&r=float
No Zend Extensions:          http://bugs.php.net/fix.php?id=31824&r=nozend
MySQL Configuration Error:   http://bugs.php.net/fix.php?id=31824&r=mysqlcfg

Reply via email to