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 ); Quote 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 while( ($fname = readdir( $dir )) !== false) Did you try it??? Quote 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() Quote 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>'; Quote 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 if you want to find all occurrences, use preg_match_all() When you are checking one line, for one occurrence, just use preg_match(). Quote Link to comment https://forums.phpfreaks.com/topic/236370-preg_match-multiple-finds/#findComment-1215476 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.