Okay, I have a problem. I need to display multilple output of a file with a similar file name
I.E.
file1: 6002010.pdf
file2: 6002010.mmddyyyy.pdf
Now the first part of the file stays the same, but there is a time stamp on modified versions of the file. But in my output I need to display all the files with the 6002010.
Could I use a wildcard such as 6002010* to get all the files to output on the screen? Or do I need to use a regular expression? GLOB maybe?
Need help with PHP wildcards or regular expressions
Moderator: General Moderators
-
prototype18
- Forum Commoner
- Posts: 25
- Joined: Wed Aug 18, 2010 9:52 am
- Jonah Bron
- DevNet Master
- Posts: 2764
- Joined: Thu Mar 15, 2007 6:28 pm
- Location: Redding, California
Re: Need help with PHP wildcards or regular expressions
Yes, regular expression. Loop through all files, and check this expression with preg_match().
The ^ at the beginning says "This can't just be in the string, this match must start at the beginning.
The first backslash (\) escapes the first dot to indicate that it's a literal dot.
The next dot matches anything but whitespace.
The first * states that the dot can reoccur as many times as necessary.
Then there's another escaped dot (\.)
Then pdf
Then $ which requires that to be the end of the string.
Code: Select all
/^6002010\..*\.pdf$/iThe first backslash (\) escapes the first dot to indicate that it's a literal dot.
The next dot matches anything but whitespace.
The first * states that the dot can reoccur as many times as necessary.
Then there's another escaped dot (\.)
Then pdf
Then $ which requires that to be the end of the string.