Reputation: 1764
I'm trying to get a list of mp3 files within a directory (/music/category/). Then I trim the directory, and then trim the mp3 extention.
The problem I'm getting with some files is that if the file name begins with the letters a,u,d,i,o (audio) as found in the string of line 3, it trims them.
So a song named "awesome" ends up displaying as "wesome".
Anyone know why this is?
$files = glob('audio/' . $category . '/*.{mp3}', GLOB_BRACE);
foreach($files as $file) {
$title = trim($file, '/audio/' . $category . "/");
$withoutExt = preg_replace("/\\.[^.\\s]{3,4}$/", "", $title);
echo $withoutExt;
}
Upvotes: 0
Views: 67
Reputation: 1271
I would do it this way:
$it = new FilesystemIterator('audio/' . $category, FilesystemIterator::SKIP_DOTS);
foreach ($it as $fileinfo) {
echo $fileinfo->getBasename('.mp3'). "\n";
}
or:
$files = glob('audio/' . $category . '/*.{mp3}', GLOB_BRACE);
foreach($files as $file) {
echo pathinfo($file, PATHINFO_FILENAME);
}
Upvotes: 1