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.