PHP 该怎么检测文件的编码呢

WBOY
Release: 2016-06-13 13:49:51
Original
989 people have browsed it

PHP 该如何检测文件的编码呢
用户上传一个文件,页面上显示出内容,整个网站都是UTF-8,用户如果上传了GB的文件,就显示出乱码。
可以用mb_convert_encoding($text,   "UTF-8 ",   "GBK ");来转换,但如何确定用户上传的是GB编码的文件呢?

------解决方案--------------------
mb_check_encoding -- Check if the string is valid for the specified encoding

------解决方案--------------------
貌似楼上写错了
mb_detect_encoding( $string )
------解决方案--------------------
iconv也可以。。。。
------解决方案--------------------
$temstr=file_get_contents($path);
$encode = mb_detect_encoding($temstr, "ASCII,UTF-8,CP936,EUC-CN,BIG-5,EUC-TW ");
$temstr=mb_convert_encoding($temstr, "CP936 ", $encode);

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template