dreamwest Posted February 4, 2009 Share Posted February 4, 2009 Im trying to match an extension of a file, but its allowing capital JPG to be included How can i ignore files that are capitals: Ignore - photo.JPG Match - photo.jpg $match = preg_match_all('/href="(.*?\.(jpg|jpeg))"/i', $html, $matches); Quote Link to comment https://forums.phpfreaks.com/topic/143737-preg_match_all/ Share on other sites More sharing options...
Snart Posted February 4, 2009 Share Posted February 4, 2009 The /i at the end of your pattern indicates case insensitivity.... Quote Link to comment https://forums.phpfreaks.com/topic/143737-preg_match_all/#findComment-754163 Share on other sites More sharing options...
dreamwest Posted February 4, 2009 Author Share Posted February 4, 2009 Thanks. That was it. Quote Link to comment https://forums.phpfreaks.com/topic/143737-preg_match_all/#findComment-754167 Share on other sites More sharing options...
.josh Posted February 4, 2009 Share Posted February 4, 2009 doing jpe?g instead of (jpg|jpeg) is more efficient. Quote Link to comment https://forums.phpfreaks.com/topic/143737-preg_match_all/#findComment-754273 Share on other sites More sharing options...
nrg_alpha Posted February 4, 2009 Share Posted February 4, 2009 $str = '<a href=\'/some_folder/some_file.jpeg\'>...</a>...<A HREF="/SOME_FOLER/SOME_FILE.JPG">...</a>...<a href="/some_folder/some_file.gif">...</a>'; // example links... preg_match_all('#href=([\'"])([^.]+\.jpe?g)\1#i', $str, $matches); echo '<pre>'.print_r($matches[2], true); Output (via pre and print_r): Array ( [0] => /some_folder/some_file.jpeg [1] => /SOME_FOLER/SOME_FILE.JPG ) Quote Link to comment https://forums.phpfreaks.com/topic/143737-preg_match_all/#findComment-754277 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.