I have a folder that I scan in a php page, introducing all of the file names (and directory names) into the array called struct, which I have to then analyze and check two things:
1) if the filename matches a pattern of 5 to 8 lowercase letters followed by and underscore, two numbers and ends with the .jpg extension, for which I tried using
$pattern = '~[a-z]{5,8}_\d{1,2}\.jpg~';
2) get the number from the file name and pass it as an int, for which I tried using
$getnumber = '~(?<=_)\d+(?=\.)~';
The first pattern seems to work, even when called upon with
if ((preg_match($pattern, $entry) === 0) && (!in_array($entry, $wrongformat)))
but trying to get the numbers of the files with
$temp[] = preg_grep($getnumber, $struct);
print_r($temp);
returns 1 in every element. How can I get the actual number inside the file name?
This is only the tip of the iceberg, it needs to be coordinated with other systems, so using something simple like explode is not something that is usable in the current setup, for various reasons (chief of which is because Boss said so). My current regex experience is 4 hours of Google-fu, so ANY help would be appreciated.