Maison  >  Article  >  développement back-end  >  PHP中file_get_contents读取中文路径报错了怎么办

PHP中file_get_contents读取中文路径报错了怎么办

PHPz
PHPzoriginal
2016-06-06 20:46:152809parcourir

PHP中file_get_contents读取中文路径报错了的解决方法:我们只需要在中文地址获取之前添加代码【iconv('utf-8', 'gbk', $address)】即可。

PHP中file_get_contents读取中文路径报错了怎么办

PHP file_get_contents读取中文路径会报错怎么办?

具体问题:

PHP:file_get_contents读取中文路径会报错

比如:文件1.txt(文件内容的格式:utf-8)

file_get_contents(文件1.txt)就会报错

[function.file-get-contents]: failed to open stream: No such file or directory不用中文的文件名就可以

路径不包含中文的话就没问题

另外,编码问题这块,有没有一个好点的解决方案呢?

方法回答:

是编码问题,Windows中是使用gbk中文编码的,而PHP文件一般都是用utf-8格式保存的了。中文地址获取之前做一次iconv('utf-8', 'gbk', $address)就没有问题了。

更多相关技术文章,请访问PHP中文网

Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn