如何在PHP中的目录搜索中添加通配符名称 [英] How to add wildcard names to directory search in php

查看:61
本文介绍了如何在PHP中的目录搜索中添加通配符名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小的php脚本,它将所有文件收集到一个目录中。此外,我正在清理此名称数组以跳过不需要的名称:

I've got a small php script that will gather all files in a directory. Futhermore, I'm cleaning through this array of names to skip over the ones I don't want:

$dirname = "./_images/border/";
$border_images = scandir($dirname);
$ignore = Array(".", "..");
  foreach($border_images as $border){
    if(!in_array($border, $ignore)) echo "TEST".$border;    
}

此目录将包含我要查找的图像。在这些图像中,每个图像都会有一个缩略图版本和一个全尺寸版本。我打算将每张图片都标记为*-缩略图或*-完整,以便于分类。

This directory would contain images that I want to find. Amongst these images, there will be a thumbnail version and a full-size version of each image. I'm planning to have each image either labeled *-thumbnail or *-full to more easily sort through.

我试图找到的是一种方法,最好使用$ ignore数组,添加一个通配符字符串,该字符串将由检查条件识别。例如,在$ ignore数组中添加* -full将使带有此标记的文件在文件名中的任何位置被忽略。我很确定in_array不会接受这一点。如果这不可能,则可以使用正则表达式吗?如果是这样,我的表情是什么?

What I'm trying to find is a way to, preferably with the $ignore array, add a wildcard string that will be recognized by a check condition. For example, adding *-full in my $ignore array would make that files with this tag, anywhere in their filenames, would be ignored. I'm pretty sure the in_array wouldn't accept this. If this isn't possible, would using regular expressions be possible? If so, what would my expression be?

谢谢。

推荐答案

您可能正在寻找php的函数 glob()

You're probably looking for php's function glob()

$files_full = glob('*-full.*');

这篇关于如何在PHP中的目录搜索中添加通配符名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆