Unable to read UTF-8 file names

Unable to read UTF-8 file names from the Windows file system (the main Windows language is English)

<?php

$path_to_read = 'D:\music';

class AudioFilterIterator extends FilterIterator
{
    public function accept()
    {
        return (strpos(parent::current(), '.mp3'));
    }
}

$object = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path_to_read));

$iterator = new AudioFilterIterator($object);

echo "<pre>";

$files = array();

foreach($iterator as $file)
{
    echo $file . "\n";
}

So, for example, I have a file called "10 Hört auf.mp3", but as an output I get "10 Hort auf.mp3"

How can i fix this?

+5
source share
2 answers

It is not possible to get through this error because PHP runs under WinAPI, which does not have reasonable support for UTF-8.

0
source

You can do this easily using the iconv function. Example for windows:

iconv("WINDOWS-1250", "UTF-8", $name);
0
source

All Articles