Page 1 of 1

Searching File Name For String With PHP

Posted: Sat Oct 25, 2008 5:41 pm
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.

Re: Searching File Name For String With PHP

Posted: Sat Oct 25, 2008 6:46 pm
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".