March 2, 2012
How to get OS default encoding?
Question by alex347
What is the proper way of getting default OS encoding? For Linux it can be found here: /etc/sysconfig/i18n
If you think the best way is to read from that file, then can I rely it will work on all modern major Linux distributions? What about Windows?
Answer by Starx
The best way to detect encoding, is from the piece of text you are trying to read from.
Use mb_detect_encoding()[docs here] function
$str = "....."; //use you own logic to get the text
echo mb_detect_encoding($str);
Adding on to @Evert
Encoding happens when characters are displayed on the screen or CLI interface. It is not OS dependent, rather content specific.