|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-10-05 11:20 UTC] kraghuba at in dot ibm dot com
Description:
------------
str_split() returns extra charecter when given string is not mulitple of given length. for example if the given string size is 22 and split length is 5, then the last element of the returned array contains 5 or more than 5 chars, which is wrong. The last element of the return array should only contain 2 chars.
This behavior is only noticed on PHP6 with UNICODE ON
Reproduce code:
---------------
<?php
$str = 'Testing str_split()';
$split_length = 5;
var_dump( str_split($str, $split_length) );
?>
Expected result:
----------------
array(4) {
[0]=>
unicode(5) "Testi"
[1]=>
unicode(5) "ng st"
[2]=>
unicode(5) "r_spl"
[3]=>
unicode(4) "it()"
}
Actual result:
--------------
array(4) {
[0]=>
unicode(5) "Testi"
[1]=>
unicode(5) "ng st"
[2]=>
unicode(5) "r_spl"
[3]=>
unicode(8) "it()^@E^@1"
}
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 19:00:02 2025 UTC |
I tried fixing the bug, in my opinion a single line should be changed. Sorry, I don't know if this is the right place to post the patch. Here it is: Index: ext/standard/string.c =================================================================== RCS file: /repository/php-src/ext/standard/string.c,v retrieving revision 1.655 diff -u -r1.655 string.c --- ext/standard/string.c 7 Oct 2007 05:15:06 -0000 1.655 +++ ext/standard/string.c 15 Nov 2007 17:29:00 -0000 @@ -7802,7 +7802,7 @@ } if (p != (str.s + str_len * charsize)) { - add_next_index_zstrl(return_value, str_type, ZSTR(p), (str.s + str_len * charsize - p), 1); + add_next_index_zstrl(return_value, str_type, ZSTR(p), (str.s + str_len * charsize - p)/charsize, 1); } } /* }}} */