UTF-8,PHP,Win7-现在有解决方案可以使用php在Win 7上保存UTF-8文件名吗? [英] UTF-8, PHP, Win7 - Is there a solution now to save UTF-8-filenames on Win 7 using php?

查看:167
本文介绍了UTF-8,PHP,Win7-现在有解决方案可以使用php在Win 7上保存UTF-8文件名吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新:只是为了不让您通读所有内容:PHP始于 7.1.0alpha2在Windows上支持UTF-8文件名. (感谢Anatol-Belski!)

Update: Just to not make you reading through all: PHP starting with 7.1.0alpha2 supports UTF-8 filenames on Windows. (Thanks to Anatol-Belski!)

在stackoverflow上跟随一些链接链,我找到了答案的一部分:
https://stackoverflow.com/a/10138133/3716796 (作者是Umberto Salsi)
(并且在相同的问题上:Artefacto的 https://stackoverflow.com/a/2950046/3716796 )
简而言之:"PHP与基础文件系统以非Unicode感知程序" 进行通信",因此Windows提供给PHP的所有文件名,反之亦然. Windows自动翻译/重新编码.这会导致错误.而且您似乎无法停止自动重新编码.
(还有Artefacto的 https://stackoverflow.com/a/2888039/3716796 :
" PHP不使用广泛的WIN32 API 调用,因此您受到代码页的限制.)
然后在 https://bugs.php.net/bug.php?id=47096 有PHP的错误报告.

Following some link chains on stackoverflow I found part of the answer:
https://stackoverflow.com/a/10138133/3716796 by Umberto Salsi
(and on the same question: https://stackoverflow.com/a/2950046/3716796 by Artefacto)
In short: 'PHP communicate[s] with the underlying file system as a "non-Unicode aware program"', and because of that all filenames given to PHP by Windows and vice versa are automatically translated/reencoded by Windows. This causes the errors. And you seemingly can't stop the automatic reencoding.
(And https://stackoverflow.com/a/2888039/3716796 by Artefacto:
"PHP does not use the wide WIN32 API calls, so you're limited by the codepage.")
And at https://bugs.php.net/bug.php?id=47096 there is the bug report for PHP.

尽管尼古拉斯建议这样做,但COM对象可能起作用!
$ fs = new COM('Scripting.FileSystemObject',null, CP_UTF8);

Though on there nicolas suggests, that a COM-object might work!
$fs = new COM('Scripting.FileSystemObject', null, CP_UTF8);

也许我有时会尝试.

所以剩下的部分是我的问题:是否存在PHP6,或者它已被撤消,或者关于该主题在PHP上是否有任何新内容?

Maybe I will try that sometimes.

So there is the part of my questionleft : Is there PHP6 out, or was it withdrawn, or is there anything new on PHP about that topic?

//完整问题
有关此主题的最多问题是1至5岁. php现在可以使用保存文件 file_put_contents($ dir.'/'.$ _POST ['fileName'],$ _POST ['content']);

// full Question
The most questions about this topic are 1 to 5 years old. Could php now save a file using file_put_contents($dir . '/' . $_POST['fileName'], $_POST['content']);

当$ _POST ['fileName']为UTF-8编码时,例如Крым.xml"吗? 目前将其另存为 Крым.xml

when the $_POST['fileName'] is UTF-8 encoded, for example "Крым.xml" ? Currently it is saved as Крым.xml

我检查了fileName变量,因此可以确定它是UTF-8: echo mb_detect_encoding($ _ POST ['fileName']);

I checked the fileName variable, so I can be sure it's UTF-8: echo mb_detect_encoding($_POST['fileName']);

  1. PHP中现在有什么新功能可以实现吗?
  2. 在某些地方,我读过PHP 6可以做到,但是如果我没记错的话,PHP 6已经撤回了. ?
  3. 在Windows资源管理器中,我可以将文件名更改为Крым.xml".据我了解的旧问题和答案,如果将fileName-var简单地编码为Windows 7及其NTFS光盘使用的编码,则应该可以使用file_put_contents. 甚至还有3个声称成功的答案的旧问题:
    具有UTF-8特殊字符的PHP文件处理
    将UTF-16LE转换为UTF-8 php
    PHP:如何创建unicode文件名

    总的来说,大多数已批准的答案都说这是不可能的. 我本人已经检查了所有建议的答案,但没有一个起作用.
  4. 如何确定并以绝对精度找出Win 7和Explorer的编码方式,将文件名保存在NTFS光盘上并使用德语设置? 如前所述:我可以在资源管理器中创建文件Крым.xml".
  1. Is there now anything new in PHP that could accomplish it?
  2. At some places I read PHP 6 would be able to do it, but PHP 6 if i I remember right, has been withdrawn. ?
  3. In Windows Explorer I can change the name of a file to "Крым.xml". As far as I have understood the old questions&answers, it should be possible to use file_put_contents if the fileName-var is simply encoded to the encoding used by windows 7 and it's NTFS disc. There is even 3 old question with answers that claim to have succeeded:
    PHP File Handling with UTF-8 Special Characters
    Convert UTF-16LE to UTF-8 in php
    and PHP: How to create unicode filenames

    Overall and most approved answers say it is not possible. I checked all suggested answers already myself, and none works.
  4. How to definitly and with absolute accuracy find out, in which encoding my Win 7 and Explorer saves the filename on my NTFS disc and with German language setting? As said: I can create a file "Крым.xml" in the Explorer.

我的结论:
1.将fileName(我尝试将其转换为UTF-16,UTF-16LE,ISO-8859-1和Windows-1252的文件名)移交给Windows时,file_put_contents均无法正常工作,
2.或file_put_contents只是没有实现以适当的方式调用Windows自己的文件函数的方式(因此,第二种可能性将意味着它不是错误,只是没有实现.)(例如notepad ++在创建,编写和重命名文件时没有问题.名为Крым.xml的文件.)

My conclusion:
1. Either file_put_contents doesn'T work correctly when handing over the fileName (which I tried with conversions to UTF-16, UTF-16LE, ISO-8859-1 and Windows-1252) to Windows,
2. or file_put_contents just doesn't implement a way to call Windows' own file function in the appropriate way (so this second possibility would mean it's not a bug but just not implemented.) (For example notepad++ has no problems creating, writing and renaming a file called Крым.xml.)

这是我收到的错误消息的一个示例,在这种情况下,当我使用 mb_convert_encoding($ theFilename,'Windows-1252','UTF-8')

Just one example of the error messages I got, in this case when I used mb_convert_encoding($theFilename , 'Windows-1252' , 'UTF-8')

警告:file_put_contents(dirToSaveIn/????.xml):无法打开流:第26行的C:\ aa xampp \ htdocs \ myinterface.lo \ myinterface \ phpWriteLocalSearchResponseXML.php中没有错误" 通过其他转换,我收到了其他错误消息,范围从无效字符"到根本没有识别出字符串.

"Warning: file_put_contents(dirToSaveIn/????.xml): failed to open stream: No error in C:\aa xampp\htdocs\myinterface.lo\myinterface\phpWriteLocalSearchResponseXML.php on line 26 " With other conversion I got other error messages, ranging from 'invalid characters' to no string recognized at all.

问候 约翰

推荐答案

从7.1.0alpha2开始的PHP在Windows上支持UTF-8文件名.

PHP starting with 7.1.0alpha2 supports UTF-8 filenames on Windows.

谢谢.

这篇关于UTF-8,PHP,Win7-现在有解决方案可以使用php在Win 7上保存UTF-8文件名吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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