列出文件夹中的所有文件后,尝试将文件名分隔为前缀

<?
$count = 0;
foreach (glob("images/shop/products/*.*") as $filename)
{
    $count++;
    $files[] = $filename;
}
foreach ($files as $filename)
{
echo $filename;

}
?>

This lovely script will output all files names in the specific images folder, My issue right now is figuring out how to make it pull out parts of the file name, and write it (as prefixes)

Files in the folders are named like this: category_name_price.jpg

why .jpg? because the file itself is an image and my goal is to list all the images as a quick category that shows prices below each image, but also to have it organized right.

so for example: shampoo_DoveCleaner_15.jpg or also: bodysoap_SpecialMineral_10.jpg

I plan on exploding the .jpg part and only include it in the img src tags of each product picture.

I know this might cause problems with spaces when for example i will need a longer name for the product (Head and Shoulders) but i will find a solution to that later on, I guess (if anyone see a possible quick fix for that, that will be awesome!)

eventually, I need to have prefix for each part $cat,$name,price so that I can organize the whole box right.

I apologize for asking here, I am not a php guru but I will appreciate any help. I tried different methods but nothing seems to fit what i'm trying to do.

Thank you all in advance !