PHP:如何创建Unicode文件名 [英] PHP: How to create unicode filenames

查看:123
本文介绍了PHP:如何创建Unicode文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建文件名中带有Unicode字符的文件.我不太清楚应该使用哪种编码,或者根本不可能.

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.

我有此文件,以latin1编码保存:

I have this file, saved in latin1 encoding:

$h = fopen("unicode_♫.txt", 'w');
fclose($h);

在UTF-8中,它将解码为"unicode_♫.txt".它以latin1版本将其写入磁盘(显而易见吗?).我需要保存它,因为它会与UTF-8解码一起出现.我也尝试过使用UTF-16对其进行编码,但这也不起作用.

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.

我正在使用PHP 5.2,并且希望它可以与NTFS,ext3和ext4一起使用.

I'm using PHP 5.2, and would like this to work with NTFS, ext3 and ext4.

这怎么办?

推荐答案

当前无法在Windows上完成(可能PHP 5.4将支持此方案).在PHP中,您只能使用Windows设置代码页写入文件名.如果代码页不包含字符,则不能使用它.更糟糕的是,如果Windows上的文件名中带有此类字符,则访问该文件将遇到麻烦.

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.

在Linux中,至少在ext *中,这是另一回事.您可以使用所需的任何文件名,操作系统无需担心编码.因此,如果您在UTF-8中始终使用文件名,则应该可以.但是,因为文件名不能包含值为0的字节,所以排除了UTF-16.

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.

这篇关于PHP:如何创建Unicode文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆