about the detection of file encoding, Baidu A lot of is, but there is no use, many people suggest mb_detect_encoding detection, but I do not know why I did not succeed, nothing output, see someone wrote an enhanced version, with the BOM to judge, I decisively ignored the , this thing is completely unreliable, finally according to the PHP manual in the example below the mb_detect_encoding function, wrote a detection function,
It also includes a function to automatically detect the encoding and read the file by pointing code, and the source is presented. Copy code code as follows: <?php /** * Detection file encoding * @param string $file file path * @return string|null return encoded name or NULL/&NBSP;FUNCT Ion Detect_encoding ($file) { $list = Array (' GBK ', ' UTF-8 ', ' utf-16le ', ' utf-16be ', ' iso-8859-1 '); &nbs P $STR = file_get_contents ($file); foreach ($list as $item) { $tmp = mb_convert_encoding ($str, $item, $ Item); &NBSP;IF (MD5 ($tmp) = = MD5 ($STR)) { return $it Em } } return null; } /** * Automatic parsing encoding read-in file * @param string $file file path * @param string $charset Read encoding * @return string return read content */function aut O_read ($file, $charset = ' UTF-8 ') { $list = Array (' GBK ', ' UTF-8 ', ' utf-16le ', ' utf-16be ', ' iso-8859-1 ');   ; $STR = file_get_contents ($file); foreach ($list as $Item) { $tmp = mb_convert_encoding ($str, $item, $item); MD5 ($t MP) = = MD5 ($STR)) { return mb_convert_encoding ($str, $charset, $item); &nb Sp } return "";}