Return to Snippet

Revision: 21440
at December 13, 2009 08:35 by Oldarney


Initial Code
<?php 

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

?>

Initial URL

                                

Initial Description
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

Initial Title
Fastest way to validate a path with a list of extensions

Initial Tags

                                

Initial Language
PHP