|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74958 ScanDir Have Problem with UTF8 Character in Linux
Submitted: 2017-07-20 21:03 UTC Modified: 2020-03-15 04:22 UTC
Avg. Score:4.4 ± 0.8
Reproduced:9 of 9 (100.0%)
Same Version:4 (44.4%)
Same OS:1 (11.1%)
From: global dot ninety at gmail dot com Assigned: cmb (profile)
Status: No Feedback Package: *General Issues
PHP Version: 7.1.7 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: global dot ninety at gmail dot com
New email:
PHP Version: OS:


 [2017-07-20 21:03 UTC] global dot ninety at gmail dot com
scandir Have Problem with UTF8 Character

Please check this image:

my folders and files name is UTF8 character (Farsi).

i need scan directorys for get list files with ScanDir , but this function have problem with UTF8 name.

Tested Information: (i have linux host in HostUpon)
System: Linux 2.6.32-673.8.1.lve1.4.3.el6.x86_64 #1 SMP Wed Feb 10 08:57:30 EST 2016 x86_64 
PHP Version: 7.1.7

Test script:
$files = scanDirectories('files');

public static function scanDirectories($rootDir, $allData=array()) {
        $invisibleFileNames = array(".", "..");
        $dirContent = scandir($rootDir);
        foreach($dirContent as $key => $content) {
            $path = $rootDir.'/'.$content;
            if(!in_array($content, $invisibleFileNames)) {
                if(Self::isFile($path)) {
                    $allData[] = $path;
                }elseif(Self::isDir($path)) {
                    $allData = Self::scanDirectories($path, $allData);
        return $allData;

    public static function isDir($path)
        $result = pathinfo($path);
        if (!array_key_exists("extension",$result))
            return true;
            return false;

    public static function isFile($path)
        $result = pathinfo($path);
        if (array_key_exists("extension",$result))
            return true;
            return false;


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-07-23 21:32 UTC]
To help diagnose what's happening here, could you provide the output of this loop where you are currently using print_r() to produce what's in the image?

foreach (scandir($dir) as $file) {

Basically, the urlencode() will help us make sense to what *is* showing up in the filename instead of what you expect.
 [2020-03-07 10:26 UTC]
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2020-03-07 10:26 UTC]
Please provide the information requested by pollita above.
 [2020-03-15 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Feb 23 08:01:29 2024 UTC