PHP file_exists和特殊字符,如ÅØÆ在Linux机器上

file_exists("file_å.txt");

Returns false while file is there. Is there any what to make *file_exists* to see the files with this kind of names?

Thanks.

Check which encoding your php script is in. Probably it's different from the file systems. (E.g. latin1 vs. utf-8)

try

file_exists(mb_convert_encoding("file_å.txt", "UTF-8"));

assuming the text is not utf-8

Check this answer: https://stackoverflow.com/a/2685818/190791

The solution for me was to convert to windows file format:

$winfilename= iconv('utf-8', 'cp1252', $utffilename);

I've run in to this a couple of times when for example reading filenames from an Excel and looking up a given path on disk. The problem may be that "ä" is either it's specific unicode char (\u00e4) or its "combined diaresis" form (a\u0308) ie an "a" with two dots.

Best solution since php 5.3 is to use the Normalizer library. You may need sudo apt-get install php5-intl to get the class into your PHP. After that just

$normalizer = new \Normalizer();
$normalizer->normalize($val, \Normalizer::FORM_D)

Theres a few different forms for the second argument so you'll have to look up which one you need