note 85123 modified in function.basename by felipe

From: Date: Fri, 15 Aug 2008 23:15:49 +0000
Subject: note 85123 modified in function.basename by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-143547@lists.php.net to get a copy of this message
once you have extracted the basename from the full path and want to separate the extension from the file name, the following function will do it efficiently: <?php function splitFilename($filename) { $pos = strrpos($filename, '.'); if ($pos === false) { // dot is not found in the filename return array($filename, ''); // no extension } else { $basename = substr($filename, 0, $pos); $extension = substr($filename, $pos+1); return array($basename, $extension); } } ?> --was-- once you have extracted the basename from the full path and want to separate the extension from the file name, the following function will do it efficiently: function splitFilename($filename) { $pos = strrpos($filename, '.'); if ($pos === false) { // dot is not found in the filename return array($filename, ''); // no extension } else { $basename = substr($filename, 0, $pos); $extension = substr($filename, $pos+1); return array($basename, $extension); } } http://php.net/manual/en/function.basename.php

« previous php.notes (#143547) next »