Maison  >  Article  >  développement back-end  >  如何判断file_get_contents来的数据 是什么编码

如何判断file_get_contents来的数据 是什么编码

WBOY
WBOYoriginal
2016-06-13 10:16:421307parcourir

怎么判断file_get_contents来的数据 是什么编码
如题

------解决方案--------------------
EUC-CN是GB 2312最常用的表示方法。浏览器编码表上的“GB2312”,通常都是指“EUC-CN”表示法。

不过你用 mb_detect_encoding 是不能得到正确的结果的
你把这个列表 "gb2312,gbk,utf-8" 里面的编码位置调一调看看
------解决方案--------------------
编码决定内容,内容不能决定编码, 
比如看见一个gbk汉字,也完全可以看成是两个ISO-8859-1字符
所以mb_detect_encoding只能用猜的,既然是猜,不能完全保证正确(其实也没有绝对的正确)

对file_get_contents得到的内容,如果是一个web页面,可以用meta来判断,
如果没有这样的信息,只能"猜"
------解决方案--------------------

探讨

编码决定内容,内容不能决定编码,
比如看见一个gbk汉字,也完全可以看成是两个ISO-8859-1字符
所以mb_detect_encoding只能用猜的,既然是猜,不能完全保证正确(其实也没有绝对的正确)

对file_get_contents得到的内容,如果是一个web页面,可以用meta来判断,
如果没有这样的信息,只能"猜"
Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn