php - 为什么 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
.
解决方案
根据PHP 手册
"auto" 扩展为 "ASCII,JIS,UTF-8,EUC-JP,SJIS"
但就我而言,它无法正常工作。如果我尝试使用以下代码而不是'auto'
得到预期的结果:
$upass = mb_convert_encoding($password, 'UCS-2LE', "ASCII,JIS,UTF-8,EUC-JP,SJIS");
推荐阅读
- arrays - 使数组声明适用于所有 linux shell
- android - 在所有操作系统版本中使用旧版本的 DatePicker
- sql - sql regex_replace 对来自多个表的指定列
- python - 在 Ubuntu 18.04 上打开幻灯片
- sql - 从日期差大于某个值的表中获取值
- jmeter - 断言响应数据失败
- swift - 为什么节点在 SceneKit 中的位置不一致?
- c# - 使用 Linq 表达式进行 C# 动态数据库过滤
- perl - 如何通过在 Perl 中传递其十六进制等效值(IEEE 格式)来获取浮点数?
- session - 在 WebAPI 和 WebForms 之间传递数据