Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect operating system encoding in php?

Tags:

php

I want to detect a operating system of filesystem's encoding as default, like Windows OS in different language version it will use different encoding (iso-8859-1, ms950, big5, gb2312..etc) So how can I detect the different operating system of encoding in PHP? Any idea? Thanks.

like image 772
Jasper Avatar asked Nov 30 '11 14:11

Jasper


People also ask

How to check encoding of a file PHP?

In PHP, mb_detect_encoding() is used to detect the character encoding. It can detect the character encoding for a string from an ordered list of candidates. This function is supported in PHP 4.0.

How to tell what encoding is used?

In Visual Studio, you can select "File > Advanced Save Options..." The "Encoding:" combo box will tell you specifically which encoding is currently being used for the file.

How do I check if a string is UTF-8 PHP?

You can make use of the UTF-8 validity check that is available in preg_match [PHPManual] since PHP 4.3. 5. It will return 0 (with no additional information) if an invalid string is given: $isUTF8 = preg_match('//u', $string);

How check string is encoded or not in PHP?

detect_order configuration option, or mb_detect_order() function) will be used. Controls the behaviour when string is not valid in any of the listed encodings . If strict is set to false , the closest matching encoding will be returned; if strict is set to true , false will be returned.


1 Answers

Linux does not have an encoding, filenames are stored in binary strings and may contain anything. Interpreting that in a specific encoding is up to the application. Most often this will simply be UTF-8. But yea, it depends on the 'viewer' of filenames.

Accessing the filesystem on OS/X will use UTF-8 normalization form D.

Unfortunately, I can not answer what it is on windows. Internally it's stored as a variation of UTF-16 but accessing it through PHP on my machine the api is CP-1252, but yea, this does depend on the language.

like image 134
Evert Avatar answered Oct 21 '22 05:10

Evert