Skip to content
Advertisement

Why is mb_convert_encoding returning false?

Here is my code:

static function CreateHash($password) {
    $upass = mb_convert_encoding($password,'UCS-2LE','auto');

    // note I have tried calling the following function to get the 
    // encoding type of $password and it returns ASCII
    // $encoding = mb_detect_encoding($password);
}

If I call the above function with $password = “abc123!”, mb_convert_encoding returns false.

Advertisement

Answer

According to PHP Manual

“auto” is expanded to “ASCII,JIS,UTF-8,EUC-JP,SJIS”

But in my case it did not work correctly. If I try the following code instead of 'auto' I get the expected result:

$upass = mb_convert_encoding($password, 'UCS-2LE', "ASCII,JIS,UTF-8,EUC-JP,SJIS");
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement