ämm ich bin von deinen
PHP-Code:
end(explode(".", strtolower($nfo['name'])))
ausgegangen, allerdings kommt das auch immer auf die situation an, viele wissen nich mal das in_array sämtliche sachen wie eine sting vergleich macht, aber einzeln wie dein beispiel oben ist es natürlich schneller.
es gibt viele situationen wo preg_match schneller ist als in_array wenn ich es finde kann ich nachher mal ein sehr gute bespiel posten
PHP-Code:
function microtime_float() {
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
$ext = strrchr ( 'abcs.shtml', '.' );
echo 'extension: ' . $ext;
$s = microtime_float();
for ( $i = 0; $i < 2000; ++$i ) {
if( in_array( end(explode(".", strtolower('abcs.shtml'))) , array('htm','html','shtm','shtml') ) )
continue;
}
echo '<br /><br />' . (microtime_float()-$s);
$s = microtime_float();
for ( $i = 0; $i < 2000; ++$i ) {
if( preg_match( '/s?html?/i' ,strrchr ( 'abcs.shtml', '.' ) ) )
continue;
}
echo '<br /><br />' . (microtime_float()-$s);
wenn du die funktionen für die dateiendungen nicht in die schleife packen würdst wäre in_array wieder schneller es kommt auf die situation drauf an
was natürlich noch besser ist ist folgendes
PHP-Code:
$extensions = array_flip( array( '.html','.htm', '.shtml', '.shtm' ) );
$ext = strrchr ( 'abcs.shtml', '.' );
echo 'extension: ' . $ext;
$s = microtime_float();
for ( $i = 0; $i < 2000; ++$i ) {
if( isset( $extensions[$ext] ) )
continue;
}
echo '<br /><br />' . (microtime_float()-$s);