|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48210 mb_detect_encoding() fails to detect right charset
Submitted: 2009-05-09 17:53 UTC Modified: 2009-05-09 19:10 UTC
From: nilon at kartio dot org Assigned:
Status: Not a bug Package: mbstring related
PHP Version: 5.2.9 OS: Debian Lenny
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: nilon at kartio dot org
New email:
PHP Version: OS:


 [2009-05-09 17:53 UTC] nilon at kartio dot org
mb_detect_encoding detects latin1 '?' as UTF-8 when it clearly isn't multibyte character.

Reproduce code:
var_dump(mb_detect_encoding("\xe4", 'UTF-8, ISO-8859-1'));
var_dump(mb_detect_encoding("\xe4", 'ISO-8859-1, UTF-8'));
var_dump(mb_detect_encoding("\xe4", 'ISO-8859-1'));
var_dump(mb_detect_encoding("\xe4", 'UTF-8'));

Expected result:
string(10) "ISO-8859-1"
string(10) "ISO-8859-1"
string(10) "ISO-8859-1"
bool "false"

Actual result:
string(5) "UTF-8"
string(10) "ISO-8859-1"
string(10) "ISO-8859-1"
string(5) "UTF-8"


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-05-09 17:58 UTC] nilon at kartio dot org
With strict option result is:
string(10) "ISO-8859-1"
string(10) "ISO-8859-1"
string(10) "ISO-8859-1"
string(5) "UTF-8"

Still last one should return false.
 [2009-05-09 19:10 UTC]
Please note that encoding detection is not always perfect.
Especially, when the string is too short, the wrong detection might be
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Thu Dec 07 09:01:27 2023 UTC