note 101907 deleted from function.strrchr by danbrown

From: Date: Mon, 17 Jan 2011 15:46:48 +0000
Subject: note 101907 deleted from function.strrchr by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-175836@lists.php.net to get a copy of this message
Note Submitter: nicolas at tatactic dot be ---- pnoexz at gmail dot com 06-Nov-2008 03:07 Here is my function that returns the type of a file. I fint it easier to add other types of files, and simplier than the rest i have seen around. Just to avoid a possible error, it' probably better to verify if index is set in the Array $exts with if(!isset($exts[$ext])) in place of return the index like this : else return "unknow"; <?php function findExt($filename){ $exts = array( '.jpg' => 'image', '.gif' => 'image', '.png' => 'image', '.php' => 'php', '.html' => 'html', '.swf' => 'flash', '.gz' => 'compressed', '.tar' => 'compressed', '.zip' => 'compressed' ); $ext = strrchr($filename,'.'); if(!isset($exts[$ext])){ return "unknown"; }else{ return $exts[$ext]; } } ?>

« previous php.notes (#175836) next »