Return to Snippet

Revision: 21437
at December 13, 2009 08:05 by Oldarney


Updated Code
<?php

if (preg_match('/.*\.(xls|jpg)\z/',substr('the image/is on/fire.jpg,-4'))){
 echo 'true';
}
 
?>

Revision: 21436
at December 13, 2009 08:05 by Oldarney


Updated Code
<?php
if (preg_match('/.*\.(xls|jpg)\z/',substr('the image/is on/fire.jpg,-4'))){
 echo 'true';
}
 
?>

Revision: 21435
at December 13, 2009 08:05 by Oldarney


Updated Code
<?php
 for($i = 0; $i < 1; $i++){
 	if (preg_match('/.*\.(xls|jpg)\z/',substr('the image/is on/fire.jpg,-4'))){
 	echo 'true';
	}
 
 }
?>

Revision: 21434
at December 13, 2009 08:02 by Oldarney


Initial Code
<?php
 $trialn = 1000;
 $timeS = microtime(true);
 for($i = 0; $i < $trialn; $i++){
 	if (preg_match('/.*\.(xls|jpg)\z/',substr('the image/is on/fire.jpg,-4'))){
 	echo 'true';
	}
 
 }
 $timeE = microtime(true);
 echo "<br />\n";
 printf($timeE-$timeS);
?>

Initial URL


Initial Description
I whipped this up after finding that my worst fears were true, pathinfo is slow. Top that with in_array and you've got your self some heavy code. Nothing like regex to speed things up.

This little code checks the extension of a path to see if it is a desired extension.

EDIT: the regex engine kills any speed benefits...

Initial Title
Regex Extension comparer

Initial Tags
php, extension

Initial Language
PHP