Search code examples
phpregexglob

Different glob() results from local to server (Windows vs Linux)


I'd like to select only files that starts with a number or a letter:

$files = glob($xsl_dir_path . "/[^a-zA-Z0-9]*.xsl");
$files = array_map('basename', $files);

There are 3 files: a.xsl, b.xsl, _functions.xsl. I don't want to select _functions.xsl file.

  • Result: local (Windows): a.xsl, b.xsl
  • Result: server (Linux): _function.xsl

Solution

  • You are negating the class match, try:

    $files = glob($xsl_dir_path . "/[a-zA-Z0-9]*.xsl");
    $files = array_map('basename', $files);