Bug #70114 [Opn->Nab]: mb_convert_encoding UTF-16 and UTF-16LE BOM behaviour

From: Date: Tue, 20 Jul 2021 11:42:05 +0000
Subject: Bug #70114 [Opn->Nab]: mb_convert_encoding UTF-16 and UTF-16LE BOM behaviour
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-235206@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=70114&edit=1 ID: 70114 Updated by: cmb@php.net Reported by: cph at osde dot uk Summary: mb_convert_encoding UTF-16 and UTF-16LE BOM behaviour -Status: Open +Status: Not a bug Type: Bug Package: mbstring related Operating System: ubuntu PHP Version: 5.6.11 -Assigned To: +Assigned To: cmb Block user comment: N Private report: N New Comment: Well, closing per my previous comment. Previous Comments: ------------------------------------------------------------------------ [2015-07-22 19:04:09] cph at osde dot uk thanks for investigating ------------------------------------------------------------------------ [2015-07-22 16:52:46] cmb@php.net I do not consider this behavior to be a bug. When a BOM is passed, conversion from UTF-16 strips the BOM, while conversion from UTF-16LE doesn't (both make sense). Either way you get a valid UTF-8 string. ------------------------------------------------------------------------ [2015-07-22 13:27:45] cph at osde dot uk Description: ------------ mb_convert_encoding UTF-16 and UTF-16LE BOM behaviour may be related to bug.php?id=34776 Test script: --------------- $utf16 = fgets($fh, 1024); echo bin2hex($utf16).PHP_EOL; $utf8 = iconv('UTF-16LE','UTF-8',mb_substr($utf16,1,null,'UTF-16LE')); echo bin2hex($utf8).PHP_EOL; var_export($utf8); $utf8 = mb_convert_encoding($utf16,'UTF-8','UTF-16'); echo bin2hex($utf8).PHP_EOL; var_export($utf8); $utf8 = mb_convert_encoding($utf16,'UTF-8','UTF-16LE'); echo bin2hex($utf8).PHP_EOL; var_export($utf8); Expected result: ---------------- RAW fffe48006f00740065006c00... IC 486f74656c49447c22486f74... 'Hot 16 486f74656c49447c22486f74... 'Hot 16LE 486f74656c49447c22486f74... 'Hot Actual result: -------------- RAW fffe48006f00740065006c00... IC 486f74656c49447c22486f74... 'Hot 16 486f74656c49447c22486f74... 'Hot 16LE efbbbf486f74656c49447c22... 'Hot ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=70114&edit=1

« previous php.bugs (#235206) next »