Home > Backend Development > PHP Tutorial > 用php检拆字符串编码

用php检拆字符串编码

WBOY
Release: 2016-06-13 10:40:39
Original
810 people have browsed it

用php检测字符串编码
在linux下测试通过,适用于检测网页编码,前提是安装了mb系列函数,一般用php的都装了。

   $content = file_get_contents($url);   $encode =  mb_detect_encoding($content,'CP936,UTF-8') ;   //如果是CP936,就是gbk编码,如果是UTF-8, 就是utf-8编码   if ($encode =='CP936') {      //再调用转换成utf-8编码的函数,最终确保是utf-8      $content = mb_convert_encoding ($content, 'UTF-8' ,'GBK');   }   echo $content;
Copy after login

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