|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2008-01-30 15:57 UTC] nicholsr@php.net
[2008-02-10 00:30 UTC] hirokawa@php.net
[2008-02-12 09:50 UTC] jmessa@php.net
[2008-02-16 08:58 UTC] hirokawa@php.net
[2008-02-18 14:15 UTC] jmessa@php.net
[2008-02-26 01:00 UTC] php-bugs at lists dot php dot net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 11:00:01 2025 UTC |
Description: ------------ The bounds check for the offest argument in mb_strpos appears to be a byte count rather than a character count. In the example below, $string_ascii is 21 characters long and $string_mb is 21 characters (53 bytes) long. In both cases the needle appears twice, first at position 9 and secondly at position 20. With the multibyte string example, when the offset is past the character count of the string it would be expected to return a warning but instead a warning is returned when offest is past the byte count. Reproduce code: --------------- <?php $offsets = array(20, 21, 22, 53, 54); $string_mb = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII='); $needle = base64_decode('44CC'); foreach($offsets as $i) { echo "\n-- Offset is $i --\n"; echo "--Multibyte String:--\n"; var_dump( mb_strpos($string_mb, $needle, $i, 'UTF-8') ); echo"--ASCII String:--\n"; var_dump(mb_strpos('This is na English ta', 'a', $i)); } ?> Expected result: ---------------- -- Offset is 20 -- --Multibyte String:-- int(20) --ASCII String:-- int(20) -- Offset is 21 -- --Multibyte String:-- bool(false) --ASCII String:-- bool(false) -- Offset is 22 -- --Multibyte String:-- Warning: mb_strpos(): Offset not contained in string. in ...\mb_strpos.php on line 9 bool(false) --ASCII String:-- Warning: mb_strpos(): Offset not contained in string. in ...\mb_strpos.php on line 11 bool(false) -- Offset is 53 -- --Multibyte String:-- Warning: mb_strpos(): Offset not contained in string. in ...\mb_strpos.php on line 9 bool(false) --ASCII String:-- Warning: mb_strpos(): Offset not contained in string. in ...\mb_strpos.php on line 11 bool(false) -- Offset is 54 -- --Multibyte String:-- Warning: mb_strpos(): Offset not contained in string. in ...\mb_strpos.php on line 9 bool(false) --ASCII String:-- Warning: mb_strpos(): Offset not contained in string. in ...\mb_strpos.php on line 11 bool(false) Actual result: -------------- -- Offset is 20 -- --Multibyte String:-- int(20) --ASCII String:-- int(20) -- Offset is 21 -- --Multibyte String:-- bool(false) --ASCII String:-- bool(false) -- Offset is 22 -- --Multibyte String:-- bool(false) --ASCII String:-- Warning: mb_strpos(): Offset not contained in string. in ...\mb_strpos.php on line 11 bool(false) -- Offset is 53 -- --Multibyte String:-- bool(false) --ASCII String:-- Warning: mb_strpos(): Offset not contained in string. in ...\mb_strpos.php on line 11 bool(false) -- Offset is 54 -- --Multibyte String:-- Warning: mb_strpos(): Offset not contained in string. in ...\mb_strpos.php on line 9 bool(false) --ASCII String:-- Warning: mb_strpos(): Offset not contained in string. in ...\mb_strpos.php on line 11 bool(false)