Bug #71183 [Opn->Nab]: mb_detect_encoding wrong with Windows-1252
| From: | ab@php.net | Date: | Mon, 21 Dec 2015 19:14:48 +0000 |
| Subject: | Bug #71183 [Opn->Nab]: mb_detect_encoding wrong with Windows-1252 | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-198109@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=71183&edit=1
ID: 71183
Updated by: ab@php.net
Reported by: martin at sutunam dot com
Summary: mb_detect_encoding wrong with Windows-1252
-Status: Open
+Status: Not a bug
Type: Bug
Package: mbstring related
Operating System: Ubuntu
PHP Version: 5.5.30
Block user comment: N
Private report: N
New Comment:
Thanks for the report.
Firstly, with 0x80 you append a number, not a char. Use chr(0x80).
Secondly, a longer string could have more success. It is in general hard to determine some single
byte encoding, and it's almost impossible with passing just 5 byte which all are numbers and
white space. It can even fail sometime for multibyte encoding. It is unlikely related to a buggy
behavior in any way.
Thanks.
Previous Comments:
------------------------------------------------------------------------
[2015-12-21 18:28:32] martin at sutunam dot com
Description:
------------
mb_detect_encoding doesn't detect string with Windows-1252 ( cp1252 ) encoding.
The function is supposed to return the first compatible encoding within the provided encoding list
as second param.
Even with an ASCII string like 'aaa', it refuse the Windows-1252 encoding.
Test script:
---------------
<?php
$enc = 'Windows-1252';
if (!in_array($enc, mb_list_encodings())) {
die($enc.' not supported');
}
$val = '100 '. 0x80; // ⬠sign in cp1252
echo mb_detect_encoding($val, $enc.',ISO-8859-1', true).PHP_EOL;
$val = 'aaa';
echo mb_detect_encoding($val, $enc.',ISO-8859-1', true).PHP_EOL;
Expected result:
----------------
Windows-1252
Windows-1252
Actual result:
--------------
ISO-8859-1
ISO-8859-1
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=71183&edit=1