search for a file containing...xxx

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
vurentjie
Forum Newbie
Posts: 3
Joined: Fri Feb 15, 2008 8:52 am

search for a file containing...xxx

Post by vurentjie »

hi,

i was hoping someone could help me out,
basically i am writing numerous files into a directory,these files are named and grouped similarly to this:

ref4949494_5.html
ref4949494_9.html
ref4949494_3.html

ref676766_5.html
ref676766_27.html
ref676766_3.html

basically the only static part of the filename is the reference number and the extension....the underscore number is completely random. Therefore i cannot easily tell how many files grouped by reference number there are, and what there exact filename is.
At the moment I cannot reference these entries in a corresponding database table, which would make it easy to reference by number etc.

So I am trying to find a way to do a filename search, from looking at my problem I am thinking some of my solution would use php substr, as well as regular expressions....

I would be extremely grateful if anybody could post a tip or a link to a tip, I have tried a google search but nothing helpful has come up.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: search for a file containing...xxx

Post by John Cartwright »

Take a look at glob()

Code: Select all

 
$matches = glob('/path/to/files/ref*.html');
 
echo '<pre>';
print_r($matches);
echo '</pre>';
vurentjie
Forum Newbie
Posts: 3
Joined: Fri Feb 15, 2008 8:52 am

Re: search for a file containing...xxx

Post by vurentjie »

thank you,

i managed to find a working solution, by reading the directory and using a substr search, but i will look at glob because your solution looks incredibly short.
Post Reply