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.

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!