FileSystem has no encoding types, each file can use different types of encoding, so you need to find the correct encoding to handle the file name string.
To determine the encoding of a file name, you can simply "try" to convert this name to a list of all known encoded lists and compare the original string of the file name with the converted string, if it is equal, then this encoding is what you are looking for.
Converting strings to coding types I use This method . To make this work, you can see the following code for an example.
function getActuallEncoding($text) { $encodingList = array('UTF-8', 'gb2312', 'ISO-8859-1', 'big5'); // Add more if you need. foreach($encodingList as $oneEncode) { $oneResult = iconv(mb_detect_encoding($text, mb_detect_order(), true), $oneEncode, $text); if(md5($oneResult) == md5($text)) return $oneEncode; } return "UNKNOWN"; // This return value may cause problem, just let you know. }
Hope this helps.
Gary wang
source share