Php:file_get_contents read Chinese path will error

Source: Internet
Author: User
For example: File 1.txt (format of file content: Utf-8)
file_get_contents (file 1.txt) will be an error
[function.file-get-contents]: failed to open stream: No such file or directory不用中文的文件名就可以
If the path does not contain Chinese, then there is no problem.
In addition, the coding problem of this piece, there is no better solution?
If there is, ask for the relevant article portal, thanks~

Reply content:

For example: File 1.txt (format of file content: Utf-8)
file_get_contents (file 1.txt) will be an error
[function.file-get-contents]: failed to open stream: No such file or directory不用中文的文件名就可以
If the path does not contain Chinese, then there is no problem.
In addition, the coding problem of this piece, there is no better solution?
If there is, ask for the relevant article portal, thanks~

is a coding problem, in Windows is gbk encoded in Chinese, and PHP files are generally saved in utf-8 the format. The Chinese address gets iconv('utf-8', 'gbk', $address) no problem before doing it once.

Name the file name in Chinese really very painful ~ ~ ~

It is said that you can do urlencode first and then go to fetch!! No concrete practice.

var_dump(@file_get_contents(urlencode("我是中文名").".txt"));

File_ get_ Contents

Note:
If you want to open a URL with special characters (for example, a space), you need to use UrlEncode () for URL encoding.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.