简体   繁体   中英

Implement date range pattern in PHP Glob pattern

I have to search directory names in PHP . I have a date range and the folder names contains the date on which they were created. So I need to implement a date range pattern in glob function.

Edit : Like I have to get the directories which were created between 10/11/2016 to 12/11/2016 . The directory name is saved like H1346579_20161110123456 So, here the date is written in 20161110 . I have to search this pattern in directory names.

Change 20161110 20161111 as disired.

foreach(glob('you_dir/*', GLOB_ONLYDIR) as $mydir) 
{
    if (preg_match('/20161110|20161111/i', $mydir)) {
    $array_dirs[] = $mydir;
    echo "<br> ";      
    echo $mydir;
}}

or in case you want an array print_r($array_dirs);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM