Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我保存了名为“File1.txt”的文件,内容(英语和希伯来语)“שלום hello”。它的编码是Unicode。当我执行“readfile”并发送标头时:
Content-type: text/plain;charset=utf-8
希伯来字符消失。奇怪的是,当我再次打开文件时,我看到了希伯来字符(Unicode 支持希伯来语),而 UTF-8 扩展了 Unicode,所以理论上我不需要进行任何转换。我该怎么办?
“其编码 [ing] 是 Unicode”这一行毫无意义。Unicode 可以通过多种方式在文本文件中表示(UTF-8 就是其中之一)。
如果您的意思是 - 它在记事本中保存为 Unicode,这意味着该文件是 UTF-16LE。发送相应的标头:
Content-type: text/plain;charset=utf-16
它会起作用的。
要回答标题中的问题,通常iconv()在 PHP 中使用该函数在编码之间进行转换。不过请注意 - 它可能在托管环境中的 Web 服务器上不可用。
iconv()