Searching File Name For String With PHP

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
Shane.Jeffery
Forum Newbie
Posts: 1
Joined: Sat Oct 25, 2008 5:41 pm

Searching File Name For String With PHP

Post by Shane.Jeffery »

Hey guys.

I have some files on my web server and I need to search through their files name with a certain string. That string will change based upon the record that the loop is on (using a foreach loop to run through my array).

Right now, the files are named like such -- ESC-440_Paper_Bassalee.

Therotically, if I could get all of the file names in that specific folder to be converted to string names, that would be ideally. Then I could just explode the strings with the "_" delimiter and then search the arrays for the relationship.

Anyone have ANY idea how to handle this?

Thanks.
User avatar
Syntac
Forum Contributor
Posts: 327
Joined: Sun Sep 14, 2008 7:59 pm

Re: Searching File Name For String With PHP

Post by Syntac »

Not sure what you're asking here, but...

Code: Select all

$array = array();
 
foreach( scandir( "/path/to/a/directory" ) as $filename )
    $array[] = explode( "-", $filename );
...might be what you're looking for. Although you may want to exclude files like ".", "..", and ".DS_Store".
Post Reply