I am trying to search a list of files and only perform work on the files that have names that contain a few values in an array. I am hoping to not have to loop through the array each time I have a new filename.
ala-
$needle = array('blah', 'bleh');
foreach($file_list as $file)
{
foreach($needle as $need)
if(strstr($file, $need) !== false)
{
// do something...
}
}
I just need to know if one of the strings in the array is in the filename, not the location of the string.
I would like to use something similar to strstr() but it does not allow an array to be used as the needle.
i.e.-
if(strstr($haystack, array('blah', 'bleh')))
{
// do something...
}
I would prefer to stay away from regular expressions, it seems to be a sledge for a hammer's job. any ideas?
break 2;when you find the first occurrence php.net/manual/en/control-structures.break.phpstrstr()