#44014 [Asn->Fbk]: mb_convert_encoding 'destroys' first character (UTF16->UTF8)
| From: | hirokawa@php.net | Date: | Sat, 16 Feb 2008 12:17:13 +0000 |
| Subject: | #44014 [Asn->Fbk]: mb_convert_encoding 'destroys' first character (UTF16->UTF8) | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-122344@lists.php.net to get a copy of this message | ||
ID: 44014
Updated by: hirokawa@php.net
Reported By: michael202 at gmx dot de
-Status: Assigned
+Status: Feedback
Bug Type: mbstring related
Operating System: Win XP
PHP Version: 5.2.5
Assigned To: hirokawa
New Comment:
BOM of Unicode is not supported by encoding conversion function
in mbstring.
And big endian is default in UTF-16. Please specify 'UTF-16LE'
if you need to specify little endian format.
Try,
<?php
$utf16 = chr(0).chr(0x4d).chr(0).chr(0x6f); //'Mo'
$utf8 = mb_convert_encoding($utf16, 'UTF-8', 'UTF-16');
echo($utf8 . "\n"); // -> Mo
?>
or
<?php
$utf16 = chr(0x4d).chr(0).chr(0x6f).chr(0); //'Mo'
$utf8 = mb_convert_encoding($utf16, 'UTF-8', 'UTF-16LE');
echo($utf8 . "\n"); // -> Mo
?>
Previous Comments:
------------------------------------------------------------------------
[2008-02-05 05:10:37] jani@php.net
Assigned to the mbstring maintainer.
------------------------------------------------------------------------
[2008-02-01 12:08:07] michael202 at gmx dot de
Description:
------------
mb_convert_encoding 'destroys' first character when
converting from UTF16 to UTF8
(iconv works).
Reproduce code:
---------------
$utf16 = chr(0xFF).chr(0xFE).chr(0x4d).chr(0).chr(0x6f).chr(0); //'Mo'
$utf8 = mb_convert_encoding($utf16, 'UTF-8', 'UTF-16');
echo($utf8 . "\n"); // -> ´++´¢ìo
$utf8 = iconv('UTF-16', 'UTF-8', $utf16);
echo($utf8 . "\n"); // -> Mo
Expected result:
----------------
mb: (BOM8)Mo
iconv: Mo
(BOM8) is a placeholder
Actual result:
--------------
mb: (BOM8)´¢ìo (copied from cmd shell)
iconv: Mo
(BOM8) is a placeholder
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=44014&edit=1