php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47018 mb_detect_encoding does not detect
Submitted: 2009-01-06 11:13 UTC Modified: 2009-02-12 01:00 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: joao dot rebelo at pchouse dot pt Assigned:
Status: No Feedback Package: mbstring related
PHP Version: 5.2.8 OS: Windows XP SP3
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: joao dot rebelo at pchouse dot pt
New email:
PHP Version: OS:

 

 [2009-01-06 11:13 UTC] joao dot rebelo at pchouse dot pt
Description:
------------
mb_detect_encoding always detect the input string encode as the first in the encoding list supplied, in this case because the first in the list is  UTF-8 always detect as UTF-8, even if the string is  in another encode, if no encoding list is supplied always detect as ASCII.

Reproduce code:
---------------
    function conv2latin($values2conv){
     $encode = mb_detect_encoding($vl2conv, 'utf-8, ISO-8859-1', true);
        if(is_array($values2conv)){
            foreach($values2conv as $key2conv=>$vl2conv){
                $encode = mb_detect_encoding($vl2conv);
                if( strtoupper($encode) != "ISO-8859-1"){
                    $vl2conv = iconv($encode, 'ISO-8859-1', $vl2conv);
                }
              $return[$key2conv]=$vl2conv;
            }
        }elseif(!empty($values2conv)){
           $encode = mb_detect_encoding($vl2conv);
           if( strtoupper($encode) != "ISO-8859-1" ){
                    $return = iconv($encode, 'ISO-8859-1', $values2conv);
                }
        }
        return $return;

return $values2conv;
    }//end function

Expected result:
----------------
The function is pretending to return the string as is if the input string is in ISO-8859-1 if not is pretending to convert the string from UTF-8 to ISO-8859-1 and return the converted string.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-02-04 22:23 UTC] jani@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/


 [2009-02-12 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 15:01:34 2025 UTC