note 101907 added to function.strrchr

From: Date: Mon, 17 Jan 2011 15:46:10 +0000
Subject: note 101907 added to function.strrchr
Groups: php.notes 
Request: Send a blank email to php-notes+get-175835@lists.php.net to get a copy of this message
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]; } } ?> ---- Server IP: 217.71.118.186 Probable Submitter: 88.147.24.1 ---- Manual Page -- http://www.php.net/manual/en/function.strrchr.php Edit -- https://master.php.net/note/edit/101907 Del: integrated -- https://master.php.net/note/delete/101907/integrated Del: useless -- https://master.php.net/note/delete/101907/useless Del: bad code -- https://master.php.net/note/delete/101907/bad+code Del: spam -- https://master.php.net/note/delete/101907/spam Del: non-english -- https://master.php.net/note/delete/101907/non-english Del: in docs -- https://master.php.net/note/delete/101907/in+docs Del: other reasons-- https://master.php.net/note/delete/101907 Reject -- https://master.php.net/note/reject/101907 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#175835) next »