PHP defining file system encoding

I need to save files with non-Latin file names in a file using PHP.

I want to make this work cross-platform. How do I know which encoding I can use to write a file? I understand that many modern file systems are based on UTF-8 (is that right?), But I doubt that Windows XP (for example).

So is there a reliable detection mechanism?

+7
filesystems php unicode
source share
2 answers

Not the answer to your question, but if you don't need to perform extensive operations at the file system level (e.g. search, sort ...), there is a good cross-platform workaround for the problem described in this SO question : URLEncode() file names .

 Hörensägen.txt 

turns into

 H%c3%b6rens%c3%a4gen.txt 

which should be safe to use on any file system and capable of displaying any UTF-8 character.

I find it much preferable to try “natively” to deal with host OS capabilities, which is guaranteed to be complex and error prone (in addition to differences in the operating system, I am sure that different file system formats are FAT16, FAT32, NTFS, extFS versions 1/2/3 .... bring your own set of rules.)

+5
source share

Not an answer, but ... WinXP is based on UTF-8 (according to Jeffrey Richter’s book "CLR via C #"), and all ASCII WinAPI functions are just wrappers for such UTF-8s.

-2
source share

All Articles