简体   繁体   English

在 PHP Glob 模式中实现日期范围模式

[英]Implement date range pattern in PHP Glob pattern

I have to search directory names in PHP .我必须在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.所以我需要在 glob 函数中实现一个日期范围模式。

Edit : Like I have to get the directories which were created between 10/11/2016 to 12/11/2016 .编辑:就像我必须获取在10/11/201612/11/2016之间创建的目录。 The directory name is saved like H1346579_20161110123456 So, here the date is written in 20161110 .目录名称保存为H1346579_20161110123456所以,这里的日期写在20161110 I have to search this pattern in directory names.我必须在目录名称中搜索此模式。

Change 20161110 20161111 as disired.20161110 20161111更改为20161110 20161111

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);或者如果你想要一个数组print_r($array_dirs);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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