php 带有通配符问题的 glob,因为它列出了所有

php glob with wildcard issue as it lists all

我有这些文件名我想删除

 Desert-100x100.jpg
     Desert-1024x768.jpg
 Desert-150x150.jpg 
  Desert-300x225.jpg

但不想删除文件名

  Desert-e1536645590208-300x217.jpg
   Desert-e1536645590208-768x555.jpg

我已经使用了这些 globs 代码,我认为它正在按预期工作

   foreach(glob("Desert-*[100-9999]x[100-9999]*.{jpg,gif,png}", GLOB_BRACE) as $file){ 

  unlink ($file);


   }

但我的问题是我们想要排除某些文件类型或更具体地说包含 e1536645590208 的文件,这是动态的,我们没有控制权,所以我们可以使用 stripos 并过滤掉那些没有 e1536645590208 的文件,但我认为必须有一些 glob 参数这将使我们能够在不使用 stripos 或其他方式的情况下过滤结果。

Glob 不理解正则表达式,* 表示 0 个或多个任意字符,它不是量词。

使用这个

glob("Desert-{1,2,3,4,5,6,7,8,9}*x*.{jpg,gif,png}", GLOB_BRACE);

glob("Desert-[1-9]*x*.{jpg,gif,png}", GLOB_BRACE);

它会 select 个有数字的文件 Desert- 所以它会跳过所有有 e.....

的文件