glob to take array as an arg

php.internals

Kevin Waterson

21 years ago
Currently glob takes a string such as array glob ( string pattern [, int flags] ) I would like to make this array glob ( array patterns [, int flags] ) This would tidy up much code where a series of OR's are used to match different patterns. $arr = array('jpg', 'gif', 'tif', 'pdf', 'bmp', 'raw'); foreach(glob($arr as $file)){ echo $file; } This would be better handled interally and the sequential search should be faster handled internally. Kevin
-- "Democracy is two wolves and a lamb voting on what to have for lunch. Liberty is a well-armed lamb contesting the vote."

Kevin Waterson

21 years ago
This one time, at band camp, Kevin Waterson <kevin@oceania.net> wrote:
> array glob ( array patterns [, int flags] )
Should be array glob ( mixed pattern [, int flags] ) Kevin
-- "Democracy is two wolves and a lamb voting on what to have for lunch. Liberty is a well-armed lamb contesting the vote."

Peter Brodersen

21 years ago
On Tue, 30 Aug 2005 23:54:53 +1000, in php.internals kevin@oceania.net (Kevin Waterson) wrote:
>I would like to make this > >array glob ( array patterns [, int flags] ) > >This would tidy up much code where a series of OR's are used to match >different patterns. > >$arr = array('jpg', 'gif', 'tif', 'pdf', 'bmp', 'raw'); >foreach(glob($arr as $file)){ echo $file; }
glob is currently extremely flexible in its input with the right flags and can expand a list. Eg: print_r(glob("*.{jpg,gif,tif,pdf,bmp,raw}",GLOB_BRACE)); If all you want is to supply glob() with a list of full or partial patterns I think the desired functionality is already present.
-- - Peter Brodersen

Kevin Waterson

21 years ago
This one time, at band camp, Peter Brodersen <php@ter.dk> wrote:
> >$arr = array('jpg', 'gif', 'tif', 'pdf', 'bmp', 'raw'); > >foreach(glob($arr as $file)){ echo $file; } > > glob is currently extremely flexible in its input with the right flags > and can expand a list. Eg: > > print_r(glob("*.{jpg,gif,tif,pdf,bmp,raw}",GLOB_BRACE));
True, but not available to all. It is GNU. Kevin
-- "Democracy is two wolves and a lamb voting on what to have for lunch. Liberty is a well-armed lamb contesting the vote."

Peter Brodersen

21 years ago
On Wed, 31 Aug 2005 11:39:04 +1000, in php.internals kevin@oceania.net (Kevin Waterson) wrote:
>> print_r(glob("*.{jpg,gif,tif,pdf,bmp,raw}",GLOB_BRACE)); > >True, but not available to all. It is GNU.
You are right - I missed that win32 uses win32/glob.h I think a better solution is just to create an emulation for GLOB_BRACE. This is nothing new, GLOB_ONLYDIR is already emulated on systems not using the GNU C library (where GLOB_EMULATE_ONLYDIR is defined instead) since 4.3.3. On one hand it would be nice with more cross-platform-compatibility. Using local libraries might create incompatibility, forcing users to make usage of PEAR libraries and such instead of native functions (though File_Find, that has just reached stable for a 1.0.x-release, could be an alternative). On the other hand, more code would make require more maintenance. Not that it seems like glob.h is that troublesome.
-- - Peter Brodersen

Kevin Waterson

21 years ago
This one time, at band camp, Peter Brodersen <php@ter.dk> wrote:
> If all you want is to supply glob() with a list of full or partial > patterns I think the desired functionality is already present.
But not on all platforms. Kevin
-- "Democracy is two wolves and a lamb voting on what to have for lunch. Liberty is a well-armed lamb contesting the vote."