note 82232 deleted from function.substr by danbrown

From: Date: Fri, 28 Nov 2008 20:17:33 +0000
Subject: note 82232 deleted from function.substr by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-147195@lists.php.net to get a copy of this message
Note Submitter: dev at arthurk dot com ---- Here is a quick and easy way to get the base name and the extension of a file. It also handles filenames like foo-1.0.1.tar (where foo-1.0.1 is the base, and .tar is the extension). <?php $file_basename = substr($filename, 0, strripos($filename, '.')); // strip extention $file_ext = substr($filename, -1 * strripos($filename, '.')); ?> Notice the use of "strripos()" instead of "stripos()". If you need to detect .tar.gz, etc. as the ext (starting at the first dot), substitute "stripos" for "strripos".

« previous php.notes (#147195) next »