1

I am using php glob() function to find matching files in a directory.

glob("*.txt");

It works for filenames with ascii characters e.g. sports.txt, frys.txt etc. However, it does not work with filenames that contain non-ascii character such as pénètre.txt.

Any thoughts?

FoxShrill
  • 91
  • 1
  • 8
  • as far as I know, PHP does not offer native Unicode support. PHP only supports a 256-character set. – Asim Jun 28 '15 at 00:20

1 Answers1

1

I tried to run this code to my local computer

<?php
foreach (glob("*.html") as $filename) {
  echo "$filename size " . filesize($filename) . "\n<br>";
}
?>

and I included a file named pènétre as you wrote, but I got a clear output without any error:

cookie.html size 357 
pénètre.html size 7719 

My PHP version is 1.6.2. Try to run this code as well and tell me if you experience any problem.

Ruben Rizzi
  • 342
  • 1
  • 3
  • 20
  • 1
    You are correct. However, the problem comes in this scenario glob("*.pénètre.html") where * is placed before pénètre.html and I am using windows. – FoxShrill Jun 28 '15 at 04:16
  • I see. If you cannot use the wildchar glob("*.html") and you type any non-ascii character in the function, you have to escape those with \. Try glob("\\*.pénètre.html"), and if the filename is *.pénètre.html, it should work (I tried in my local machine, I have a Mac though). – Ruben Rizzi Jun 28 '15 at 14:28
  • I mean, * is an ascii character, but since it has a special meaning, you have to escape it as well. For example if your filename is ¢*.pénètre.html, your function will be glob("\¢\\*.pénètre.html") – Ruben Rizzi Jun 28 '15 at 14:42