Alright, I got tons of help last time and now I'm stuck again... I have the following list: thumbs/thumb.Aaliyah-1.jpg thumbs/thumb.Aaliyah-22.jpg thumbs/thumb.Aaliyah-3.jpg thumbs/thumb.Abi-Titmuss-1.jpg thumbs/thumb.Abi-Titmuss-2.jpg thumbs/thumb.Abi-Titmuss-3.jpg thumbs/thumb.Ada-Nicodemou-6.jpg thumbs/thumb.Ada-Nicodemou-7.jpg thumbs/thumb.Adele-Silva-3.jpg thumbs/thumb.Adele-Silva-4.jpg thumbs/thumb.Adriana-Karembeu-1.jpg Code (markup): Using this script: <?php foreach (glob("thumbs/*.jpg") as $dirname) { echo "$dirname<br />"; } ?> PHP: Now I need to modify the above script to make it so I can pull out only the files with "Aaliyah" in it. Any ideas on how to do this?
<?php foreach (preg_grep('/aaliyah/i', glob("thumbs/*.jpg")) as $dirname) { echo "$dirname<br />"; } ?> PHP: Untested but should work. www.php.net/preg_grep EDIT: A better way could be using just glob though. <?php foreach (glob("thumbs/*aaliyha*.jpg") as $dirname) { echo "$dirname<br />"; } ?> PHP: (But it's not case-insensitive)
Just note that it might be case-sensitive on some systems. If it is, you can change all file names to lower case and it shouldn't be a problem anymore.