Home >Backend Development >PHP Problem >What should I do if the Chinese file name of fopen under PHP is garbled?
Solution to the garbled Chinese file name in fopen under php: First encode the file name, the code is [$fileName = iconv('UTF-8', 'GBK', $fileName)]; then save the original Chinese file name; finally, create the file through file name encoding.
Solution to the garbled Chinese file name in fopen under php:
Encode the file name.
<?php $fileName = __DIR__ . '\测试.txt'; $fileName = iconv('UTF-8', 'GBK', $fileName); $fp = fopen($fileName, 'w'); fwrite($fp, '这是中文内容'); fclose($fp); echo $fileName.'<br>'; if(file_exists($fileName)){ echo 'hhhhh'; } ?>
Result:
But look at the file name output on the page:
So when you want When outputting a file name on the page and needing to save the file, you can save the original Chinese file name first, and then create the file through file name encoding.
Related learning recommendations: PHP programming from entry to proficiency
The above is the detailed content of What should I do if the Chinese file name of fopen under PHP is garbled?. For more information, please follow other related articles on the PHP Chinese website!