0

I can view all jpg images in a folder using the function glob:

$list = glob('../uploads/images/*.jpg');
usort(
   $list,
   create_function('$b,$a', 'return filemtime($a) - filemtime($b);')
);
foreach($list as $file)
{
    echo '<img src="../uploads/images/'.basename($file).'"/>';  

}

How do I get regular expression in the file format? I tried to accept jpg and JPG but did not work: $list = glob('../uploads/images/*.("%.+.[jJ][pP][eE]?[gG]$%i")');

Gisele
  • 65
  • 7
  • `filemtime`, `fileatime`, `filectime` afaik – u_mulder Mar 10 '16 at 19:09
  • @Gisele above link best answer is dated 2008. I have added a similar [answer](http://stackoverflow.com/a/35925596/3294262) with use of anonymous function, introduced in PHP in 2010. – fusion3k Mar 10 '16 at 19:35
  • @fusion3k Thanks this worked for me. How do I get regular expression in the file format? I tried to accept `jpg` and `JPG` but did not work: `$list = glob('../uploads/images/*.("%.+.[jJ][pP][eE]?[gG]$%i")');` – Gisele Mar 10 '16 at 20:14
  • I updated my doubts to not be a duplicate question. Please see – Gisele Mar 10 '16 at 20:25
  • @Gisele http://stackoverflow.com/a/10591546/3294262 – fusion3k Mar 10 '16 at 20:38
  • hahaha again a duplicate question. Thanks it worked. duplicate questions should be excluded? – Gisele Mar 10 '16 at 21:29

0 Answers0