Orionsbelter Posted May 14, 2011 Share Posted May 14, 2011 would this work to find all jpg and all png and gifs with a certain directory? $dir = opendir( "pics" ); $pics = array(); while( $fname = readdir( $dir ) ) { if ( preg_match( "/[.]jpg$/","/[.]gif$/","/[.]png$/", $fname ) ) $pics []= $fname; } closedir( $dir ); Link to comment https://forums.phpfreaks.com/topic/236370-preg_match-multiple-finds/ Share on other sites More sharing options...
jcbones Posted May 14, 2011 Share Posted May 14, 2011 Quote while( ($fname = readdir( $dir )) !== false) Did you try it??? Link to comment https://forums.phpfreaks.com/topic/236370-preg_match-multiple-finds/#findComment-1215247 Share on other sites More sharing options...
fugix Posted May 14, 2011 Share Posted May 14, 2011 if you want to find all occurrences, use preg_match_all() Link to comment https://forums.phpfreaks.com/topic/236370-preg_match-multiple-finds/#findComment-1215270 Share on other sites More sharing options...
wildteen88 Posted May 14, 2011 Share Posted May 14, 2011 An easier method is to use glob $images = glob("pics/{*.gif,*.jpg,*.png}", GLOB_BRACE); echo '<pre>'.print_r($images, true).'</pre>'; Link to comment https://forums.phpfreaks.com/topic/236370-preg_match-multiple-finds/#findComment-1215302 Share on other sites More sharing options...
jcbones Posted May 14, 2011 Share Posted May 14, 2011 Quote if you want to find all occurrences, use preg_match_all() When you are checking one line, for one occurrence, just use preg_match(). Link to comment https://forums.phpfreaks.com/topic/236370-preg_match-multiple-finds/#findComment-1215476 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.