- substr: documentation ( source)
- pathinfo: documentation ( source)
- microtime: documentation ( source)
- strrpos: documentation ( source)
- strrchr: documentation ( source)
<?php
$filename = 'fgdsahktyrewagfbdhzbvt74tf.gfdhsgfghsdf.gsdfhjgfdsg.gsfdghfdsh.dtasfghsdghg.tar.gz';
$t1 = microtime(true);
for ($i = 0; $i < 100000; ++$i) {
$e1 = substr($filename, strrpos($filename, '.') + 1);
}
$t2 = microtime(true);
for ($n = 0; $n < 100000; ++$n) {
$e2 = pathinfo($filename, \PATHINFO_EXTENSION);
}
$t3 = microtime(true);
for ($j = 0; $j < 100000; ++$j) {
$e3 = substr(strrchr($filename, '.'), 1);
}
$t4 = microtime(true);
echo '1: ' . ($t2-$t1), PHP_EOL;
echo '2: ' . ($t3-$t2), PHP_EOL;
echo '3: ' . ($t4-$t3), PHP_EOL;