检测文件编码,转换文件编码

CP936

微软的CP936通常被视为等同GBK,连 IANA 也以“CP936”为“GBK”之别名 [1]。事实上比较起来, GBK 定义之字符较 CP936 多出95字(15个非汉字及80个汉字),

mb_detect_encoding — 检测字符的编码

 mb_detect_encoding(string $str, mixed $encoding_list = mb_detect_order(), bool $strict = false): string | false

可以用array 或者 逗号分隔的字符串 来指定 encoding_list ,否则使用默认的 mb_detect_order()

mb_convert_encoding — 转换字符的编码

mb_convert_encoding(array|string $string, string $to_encoding, array|string|null $from_encoding = null): array|string|false

两者搭配效果更佳

$encode = mb_detect_encoding($file_content, ["UTF-8", "GB2312", "ASCII", "GBK", "BIG5"]);

$file_content = mb_convert_encoding($file_content, 'UTF-8', $encode);
本作品采用《CC 协议》,转载必须注明作者和本文链接
学过的东西能说出来那是最妙的,能复盘写下来那也不错
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!