Domanda

I would like to match file name from directory which I know the starting portion of the file along with underscore. The format of the files will be always mp3. For example the file name 12_title.mp3 should read to a variable if I pass 12. In the directory the starting numbers are unique

any help is appreciated thank you in advance

È stato utile?

Soluzione

Try the scandir with preg_grep will help

$myfiles=scandir("files/");  
$id="12";  
$matches=preg_grep("/".$id."_.+mp3$/i",$myfiles);
foreach($matches as $key=>$keyvalue)
{
$file=$keyvalue;
echo "Matched filename = ".$file;
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top