今天发现一段很好的代码: function characet($data) if( !empty($data) ) $fileType = mb_detect_encoding($data , array(UTF-8,GBK,LATIN1,BIG5)) ; if( $fileType != UTF-8) $data = mb_convert_encoding($data ,utf-8 , $fileType); return $data; 这个
今天发现一段很好的代码:
function characet($data){
if( !empty($data) ){
$fileType = mb_detect_encoding($data , array('UTF-8','GBK','LATIN1','BIG5')) ;
if( $fileType != 'UTF-8'){
$data = mb_convert_encoding($data ,'utf-8' , $fileType);
}
}
return $data;
}
这个在于传中文参数的时候,由于编码不同,会发生乱码现象,当参数编码不一定是GBK的时候,那就不能都转换编码了
上面的好处是,判断编码,然后转换,和谐了
原文地址:php自动识别编码转换为UTF-8, 感谢原作者分享。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 English version
Recommended: Win version, supports code prompts!

Dreamweaver CS6
Visual web development tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft