首页 > 解决方案 > 为什么 mb_convert_encoding 返回 false?

问题描述

这是我的代码:

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);
}

如果我用 $password = "abc123!" 调用上述函数,则mb_convert_encoding返回false.

标签: phpencoding

解决方案


根据PHP 手册

"auto" 扩展为 "ASCII,JIS,UTF-8,EUC-JP,SJIS"

但就我而言,它无法正常工作。如果我尝试使用以下代码而不是'auto'得到预期的结果:

$upass = mb_convert_encoding($password, 'UCS-2LE', "ASCII,JIS,UTF-8,EUC-JP,SJIS");

推荐阅读