Tested in linux with php string encoding, suitable for detecting webpage encoding, provided that the mb series of functions are installed, which are generally installed in php. $ Contentfile_get_contents ($ url); $ encodemb_detect_encoding ($ content, CP936, UTF-8); for CP936, gbk encoding is used to detect string encoding with php
The test passed in linux is suitable for detecting webpage encoding, provided that the mb series functions are installed, which are generally installed in php.
$ Content = file_get_contents ($ url); $ encode = mb_detect_encoding ($ content, 'cp936, UTF-8 '); // if it is CP936, it is gbk encoding, if it is a UTF-8, is UTF-8 encoded if ($ encode = 'cp936 ') {// call the function to convert to UTF-8 encoding, and finally ensure that it is UTF-8 $ content = mb_convert_encoding ($ content, 'utf-8', 'gbk');} echo $ content;