[英]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.