mb_detect_encoding无法正常使用Windows-1250(CP1250) [英] mb_detect_encoding doesn't properly working with Windows-1250 (CP1250)

查看:146
本文介绍了mb_detect_encoding无法正常使用Windows-1250(CP1250)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

mb_detect_encoding()中检测CP1250有问题在我的情况下,我想检测3个编码:

I have problem with detecting CP1250 in mb_detect_encoding(), in my case I want detect 3 encodings:

mb_detect_encoding($string, 'UTF-8,ISO-8859-2,Windows-1250')

但Windows不支持编码,任何解决方案?

But Windows isn't in supported encodings, any solution?

推荐答案

mb_detect_encoding 始终检测单字节编码。您可以在 mb_detect_order

mb_detect_encoding always "detects" single-byte encodings. You can read about this in the documentation for mb_detect_order:


mbstring目前实现以下编码检测
过滤器。如果以下
编码存在无效的字节序列,编码检测将失败。

mbstring currently implements the following encoding detection filters. If there is an invalid byte sequence for the following encodings, encoding detection will fail.

UTF-8,UTF-7,ASCII,
EUC-JP,SJIS,eucJP-win,SJIS-win,JIS,ISO-2022-JP

UTF-8, UTF-7, ASCII, EUC-JP,SJIS, eucJP-win, SJIS-win, JIS, ISO-2022-JP

对于ISO-8859-X,mbstring总是检测为ISO-8859 -X。

For ISO-8859-X, mbstring always detects as ISO-8859-X.

对于UTF-16,UTF-32,UCS2和UCS4,编码检测将一直失败

For UTF-16, UTF-32, UCS2 and UCS4, encoding detection will fail always.

结论:


  1. 要求检测ISO-8859-2是无意义的;它总是会告诉你是的,就是这样(除非它首先检测到UTF-8)。

  2. Windows-1250不支持,但即使它会正常工作像ISO-8859-2。

一般来说,不可能准确地检测单字节编码。如果您发现自己需要在PHP中执行此操作,则需要手动执行;不要指望非常好的结果。

In general, it is impossible to detect single-byte encodings with accuracy. If you find yourself needing to do that in PHP you will need to do it manually; don't expect very good results.

这篇关于mb_detect_encoding无法正常使用Windows-1250(CP1250)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆