Yngvarr

Generation

generate functionTue, 21 Mar 2023

convert file to utf8

function convert_to_utf8($fileName) { $fileName = str_replace('/', '\\\\', $fileName); $encoding = mb_detect_encoding($fileName); if ($encoding != 'UTF-8') { if ($encoding == 'GB18030') { $encoding = 'GBK'; } echo 'The file is not utf8, encoding is ' . $encoding . '<br>'; $str = file_get_contents($fileName); $str = mb_convert_encoding($str, 'UTF-8', $encoding); file_put_contents($fileName, $str); } }

Questions about programming?Chat with your personal AI assistant