Fastest way to validate a path with a list of extensions


/ Published in: PHP
Save to your folder(s)

Here is the research of running the scripts 10000 times, in milliseconds:

preg_match('/.*\.(jpg|gif|png)\z/',substr('the image/is on/fire.jpg,-4'))
0.29-0.27

in_array(strtolower(substr('the image/is on/fire.jpg',-3)), array('jpg','gif','png'))
0.03-0.025

switch (strtolower(substr('the image/is on/fire.jpg',-3))){
case 'jpg':
case 'gif':
case 'png':
$ec = true;
}//use $ec for return statement
0.019-0.14

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.