I would like to introduce two methods for PHP to determine the character encoding. One is to use the function mb_detect_encoding that comes with PHP, and the other is to write a function yourself to handle it. Friends in need, come and take a look.
Method 1, use mb_detect_encoding function. <?php $str=”程序员之家,欢迎大家的光临。”; echo mb_detect_encoding($str); ?> Copy after login Method 2, custom function. <?php function chkbm($string){ $bm = array(‘ASCII’, ‘GBK’, ‘UTF-8′); foreach($bm as $c){ if( $string === iconv(‘UTF-8′, $c, iconv($c, ‘UTF-8′, $string))){//转换编码后是不是相等 return $c; } } return null; } ?> Copy after login How to choose? Smart one, you decide, ha~~~ |