How to determine the encoding of the operating system in php?

I want to determine the default file system encoding operating system, for example, Windows OS in a different language version, it will use a different encoding (iso-8859-1, ms950, big5, gb2312..etc) So, how can I detect a different encoding operating system in php? Any ideas? Thanks.

+7
source share
4 answers

Linux does not have an encoding; file names are stored in binary strings and can contain anything. The interpretation of this in a particular encoding is application dependent. Most often it will be just UTF-8. But yes, it depends on the "viewer" of the file names.

Access to the file system on OS / X will use the UTF-8 form for normalization.

Unfortunately, I can’t answer that it’s on the windows. Internally, it is stored as a variant of UTF-16, but access to it through PHP on my api machine is CP-1252, but yes, it depends on the language.

+1
source

Why not use mb_detect_encoding () ?

0
source

Try

print_r( explode(";", setlocale(LC_ALL, 0))); 

Then you need to convert the code page to encoding

0
source

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.

0
source

All Articles