|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2005-05-17 18:09 UTC] wiseman1024 at gmail dot com
Description:
------------
glob() won't work (with any pattern and options whatsoever) when one directory in the current working path has matching brackets [ and ] with characters between the brackets.
This means glob() will fail if the current working directory is one of:
C:\php\[hello]
C:\php\[hello]\hello
C:\php\xxx[hello]xxx
C:\php\[hello][
It will work, for example, if the current working directory is one of:
C:\php
C:\php\[hello
C:\php\hello]
C:\php\hello[]
This seems to be a problem when using regular expressions in the implementation of glob.
Reproduce code:
---------------
/* Returns a list of files and directories, unless inside a directory with something between brackets*/
print_r(glob('*',FALSE));
Expected result:
----------------
Should always return an array with the files (assuming there are files in the current directory)
Actual result:
--------------
Nothing, because glob() returned false
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 08 16:00:01 2025 UTC |
Here's my workaround code, using opendir() and readdir() (using code from the readdir() page on this site): if ($dirh = opendir(".")) { $picfns = 0; while (false !== ($file = readdir($dirh))) { if (preg_match("/^_.*jpg$/", $file)) { $file = preg_replace("/^_/", "", $file); if ($picfns) { array_push($picfns, $file); } else { $picfns = array($file); } } } closedir($dirh); } replaces this code: $thumbfns = glob("_*.jpg"); $jpgfns = glob("*.jpg"); $picfns = array_diff($jpgfns, $thumbfns); --i;