I’m trying to create files with Unicode characters in there filenames. I don’t quite know what encoding I should use, or if it’s possible at all.
I have this file, saved in latin1 encoding:
$h = fopen("unicode_♫.txt", 'w');
fclose($h);
In UTF-8 this would decode as ‘unicode_♫.txt’. It writes it in the latin1 version to the disk (which is obvious?). I need it to be save as it would appear with UTF-8 decoding. I’ve also tried encoding it with UTF-16 but that’s not working either.
I’m using PHP 5.2, and would like this to work with NTFS, ext3 and ext4.
How can this be done?
It can’t currently be done on Windows (possibly PHP 5.4 will support this scenario). In PHP, you can only write filenames using the Windows set codepage. If the codepage, does not include the character
♫, you cannot use it. Worse, if you have a file on Windows with such character in its filename, you’ll have trouble accessing it.In Linux, at least with ext*, it’s a different story. You can use whatever filenames you want, the OS doesn’t care about the encoding. So if you consistently use filenames in UTF-8, you should be OK. UTF-16 is however excluded because filenames cannot include bytes with value 0.