keithvb Posted March 2, 2011 Share Posted March 2, 2011 Is there a better way to specify the "if (strsistr...)" line? Suppose I want to check 4 or 5 file ext's instead of just 2? <?php if ($handle = opendir('pics')) { echo 'Directory handle: ' . $handle . '<br />'; echo 'Files: <br />'; while (false !== ($file = readdir($handle))) { if ( stristr($file,("jpg")) || stristr($file,("png")) ) { echo $file . '<br />'; } } closedir($handle); } ?> thanks, Keith Link to comment https://forums.phpfreaks.com/topic/229385-stristr-problem/ Share on other sites More sharing options...
kenrbnsn Posted March 2, 2011 Share Posted March 2, 2011 Why don't you use the glob() function and just get the files with the extensions you want? <?php $files = glob('pics/*.{jpg,png,gif}',GLOB_BRACE); echo "Files: <br />\n": foreach ($files as $file) { echo basename($file) . "<br />\n": } ?> Ken Link to comment https://forums.phpfreaks.com/topic/229385-stristr-problem/#findComment-1181901 Share on other sites More sharing options...
keithvb Posted March 2, 2011 Author Share Posted March 2, 2011 Thanks, Ken. That works. Didn't know about glob Now to integrate it into the slide show I'm attempting... Keith Link to comment https://forums.phpfreaks.com/topic/229385-stristr-problem/#findComment-1181916 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.