About the PHP fopen function when creating a Chinese-named document on a Windows system garbled problem

Source: Internet
Author: User
As we all know, PHP fopen function can create a new document, but if you create this document, named in Chinese, and you use the Windows system, you will find that the Chinese part of the document name is garbled. Let's do the experiment below:

PHP script (UTF-8 encoding)


   
   $fileName = __DIR__ . '/中文文档.txt';//$fileName = iconv('UTF-8', 'GBK', $fileName);$fp = fopen($fileName, 'w');fwrite($fp, '这是中文内容');fclose($fp);?>

Execute the script above to browse the newly created document:

As you can see, the document name is garbled, but the contents of the document are not garbled.

Workaround

Remove the comment from the second sentence of the php script above, $fileName convert the UTF-8 encoding to GBK encoding, and then execute the script again, and find that the document name is not garbled:

At last

At present, this situation only found on the Windows system, on the Mac Os/linux Normal, so on the unix/linux system, no need to convert the document name encoding, if you just want to convert the document name to GBK encoding, it will be garbled, for example:

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

The above describes the PHP fopen function on the Windows system to create a Chinese named document when garbled, including the content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.