[英]Is glob() the best way to get specific files with specific string, or extension?
方法是否正确?
3种不同的数据类型:
$dir = "./content/media/artworks";
// ignore jpg-pictures if the name '_th' appears. And files with 'txt' extension.
$imgs = glob($dir.'/*{[!_th].jpg,*.[!txt]}', GLOB_BRACE);
// Just take jpg images with the name '_th'
$thumbs = glob($dir.'/*?_th.*');
// Just take files with 'txt' extensions
$txts = glob($dir.'/*?.txt');
glob 的第一个模式是错误的。 这里 * [._th]。 jpg 并不表示 before.jpg 不是“_th”,而是表示该点之前的最后一个字符不允许有 '_'。 没有“t”,也没有“h”。
使用 array_diff() 获取所有不包含拇指的 jpg 文件。
$thumbs = glob($dir.'/*_th.jpg');
$jpgWithoutThumbs = array_diff(glob($dir.'/*.jpg'), $thumbs);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.