如何在 PHP 中打开名称中包含 unicode 字符的文件?

2023-04-09php开发问题
1

本文介绍了如何在 PHP 中打开名称中包含 unicode 字符的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

例如,我有一个这样的文件名 - проба.xml,但我无法从 PHP 脚本打开它.

For example I have a filename like this - проба.xml and I am unable to open it from PHP script.

如果我将 php 脚本设置为 utf-8,那么脚本中的所有文本都是 utf-8,因此当我将其传递给 file_get_contents 时:

If I setup php script to be in utf-8 than all the text in script is utf-8 thus when I pass this to file_get_contents:

$fname = "проба.xml";
file_get_contents($fname);

我收到文件不存在的错误.这样做的原因是在 Windows (XP) 中,所有带有非拉丁字符的文件名都是 unicode (UTF-16).好的,所以我试过这个:

I get error that file does not exist. The reason for this is that in Windows (XP) all file names with non-latin characters are unicode (UTF-16). OK so I tried this:

$fname = "проба.xml";
$res = mb_convert_encoding($fname,'UTF-8','UTF-16');
file_get_contents($res);

但是由于 file_get_contents 不能接受 unicode 字符串,所以错误仍然存在...

But the error persists since file_get_contents can not accept unicode strings...

有什么建议吗?

推荐答案

这些是目前的结论:

  1. PHP 5 无法打开带有 unicode 字符的文件名,除非源文件名是 unicode.
  2. PHP 5(至少在 Windows XP 上)无法处理 unicode 中的 PHP 源代码.

因此得出的结论是这在 PHP 5 中是不可行的.

Thus the conclusion this not doable in PHP 5.

这篇关于如何在 PHP 中打开名称中包含 unicode 字符的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

PHP实现DeepL翻译API调用
DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以...
2025-08-20 php开发问题
168

PHP通过phpspreadsheet导入Excel日期数据处理方法
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的...
2024-10-23 php开发问题
287

mediatemple - 无法使用 codeigniter 发送电子邮件
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)...
2024-08-23 php开发问题
11

Laravel Gmail 配置错误
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)...
2024-08-23 php开发问题
16

将 PHPMailer 用于 SMTP 的问题
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)...
2024-08-23 php开发问题
4

关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)...
2024-08-23 php开发问题
17