2009/6/12 Michael Wallner <[email protected]>:
> Matt Wilmas wrote:
>> Hi Dmitry, Antony,
>>
>> Fixed, thanks.
>>
>
>>> Matt Wilmas wrote:
>>>> mattwil Wed Apr 1 17:05:37 2009 UTC
>>>>
>>>> Removed files: (Branch: PHP_5_3)
>>>> /php-src/ext/standard/tests/strings bug47546.phpt
>>>> Modified files: /php-src NEWS /php-src/ext/standard
>>>> php_string.h string.c Log:
>>>> MFH: explode() stuff:
>>>> - Fixed bug #47560 (explode()'s limit parameter odd behaviour) by
>>>> reverting change for bug #47546
>>
>
> In what state is this now?
>
> php_explode() does not work as expected with limit=-1 and
> php_explode_negative_limit() is not exported in php_string.h
>
> Mike
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>From a user's perspective, I would say that explode() now works as I
would expect.
When a valid delimiter is supplied with no limit, then the result is
the same as if the limit was the count of items after the split.
For negative limits (with a valid delimiter), the result is chopped by
the abs($limit).
<?php
$string = 'one.two.three.four';
$results = array();
foreach(array('Valid' => '.', 'Invalid' => '_') as $valid => $delimiter) {
$results[$valid]['No Limit'] = explode($delimiter, $string);
foreach(range(-4, 4) as $limit) {
$results[$valid][$limit] = explode($delimiter, $string, $limit);
}
}
print_r($results);
?>
outputs what I think is correct.
Array
(
[Valid] => Array
(
[No Limit] => Array
(
[0] => one
[1] => two
[2] => three
[3] => four
)
[-4] => Array
(
)
[-3] => Array
(
[0] => one
)
[-2] => Array
(
[0] => one
[1] => two
)
[-1] => Array
(
[0] => one
[1] => two
[2] => three
)
[0] => Array
(
[0] => one.two.three.four
)
[1] => Array
(
[0] => one.two.three.four
)
[2] => Array
(
[0] => one
[1] => two.three.four
)
[3] => Array
(
[0] => one
[1] => two
[2] => three.four
)
[4] => Array
(
[0] => one
[1] => two
[2] => three
[3] => four
)
)
[Invalid] => Array
(
[No Limit] => Array
(
[0] => one.two.three.four
)
[-4] => Array
(
)
[-3] => Array
(
)
[-2] => Array
(
)
[-1] => Array
(
)
[0] => Array
(
[0] => one.two.three.four
)
[1] => Array
(
[0] => one.two.three.four
)
[2] => Array
(
[0] => one.two.three.four
)
[3] => Array
(
[0] => one.two.three.four
)
[4] => Array
(
[0] => one.two.three.four
)
)
)
--
-----
Richard Quadling
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
"Standing on the shoulders of some very clever giants!"
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php