|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #54494 mb_substr() fails on "UTF-32LE"
Submitted: 2011-04-08 17:05 UTC Modified: 2011-04-09 18:59 UTC
From: rodney dot rehm at medialize dot de Assigned: cataphract (profile)
Status: Closed Package: mbstring related
PHP Version: 5.3.6 OS: Mac OS X 10.6.7 / Windows 2003
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
18 - 17 = ?
Subscribe to this entry?

 [2011-04-08 17:05 UTC] rodney dot rehm at medialize dot de
Iterating the characters of a UTF-32LE encoded string by using mb_substr() fails. Same string UTF-32BE encoded works as expected. 

Test script:

declare(encoding = 'UTF-8');

header('Content-Type: text/plain; charset=UTF-32LE');

$string = "hällö wörld\n";
$string = mb_convert_encoding($string, "UTF-32LE");
$length = mb_strlen($string, "UTF-32LE");
echo mb_convert_encoding("Length: ". $length ."\n", "UTF-32LE");

echo $string;

for ($i=0; $i < $length; $i++) {
  echo mb_substr($string, $i, 1, "UTF-32LE");


Expected result:
Length: 12
hällö wörld
hällö wörld

Actual result:
Length: 12
hällö wörld


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2011-04-09 18:59 UTC]
Automatic comment from SVN on behalf of cataphract
Log: - Fixed bug #54494: mb_substr() mishandles UTF-32LE and UCS-2LE.
 [2011-04-09 18:59 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: cataphract
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Thu Dec 03 01:01:23 2020 UTC