php Solution to readdir garbled code: 1. Modify the encoding through "mb_convert_encoding"; 2. Use the "utf8_encode" method to modify the encoding.
The operating environment of this article: Windows7 system, PHP7.1 version, DELL G3 computer
How to solve the php readdir garbled problem?
Specific problem:
PHP uses opendir readdir Chinese files are garbled
<?php //打开 images 目录 $handle = opendir("images"); //列出 images 目录中的文件 while (($file = readdir($handle)) !== false){ echo "filename: " . $file . "<br />"; } closedir($dir); ?>
The Chinese files or Chinese directories read here are null. Why is this?
Note: You need to use ajax to request data.
Solution:
windows:
echo mb_convert_encoding ($file,'UTF-8','GBK');
Linux:
echo utf8_encode($file);
Recommended learning: "PHP Video tutorial》
The above is the detailed content of How to solve the garbled problem of php readdir. For more information, please follow other related articles on the PHP Chinese website!