Home > Backend Development > PHP Tutorial > PHP中file_get_contents读取中文路径报错了怎么办

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

PHPz
Release: 2020-09-05 09:50:29
Original
2887 people have browsed it

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中文网

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template