Prusprus
Prusprus

Reputation: 8065

How to add wildcard names to directory search in 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.

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?

Thanks.

Upvotes: 0

Views: 741

Answers (3)

Sarfraz
Sarfraz

Reputation: 382806

Take a look at glob function.

glob — Find pathnames matching a pattern

Upvotes: 2

Amber
Amber

Reputation: 527123

There is a better way to do this known as glob().

Upvotes: 2

genesis
genesis

Reputation: 50974

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

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

Upvotes: 2

Related Questions