note 71797 deleted from function.basename by nlopess

From: Date: Sun, 17 Dec 2006 19:24:44 +0000
Subject: note 71797 deleted from function.basename by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-120690@lists.php.net to get a copy of this message
Note Submitter: Steve Goguen ---- Here's my function which parses out the parts of a path. It will parse out multiple extensions for files like "archive.tar.gz", returning "archive" as the basename. // EXAMPLE print_r(filename_parts("./path/filename.tar.gz")); // YIELDS Array ( [full] => ./path/filename.tar.gz [folder] => ./path/ [filename] => filename.tar.gz [basename] => filename [full_extension] => .tar.gz [extension] => gz ) // DEFINITION function filename_parts($file) { preg_match('/(.*?)(([^\\/\\\\]+?)((?:[.](\w*))*)?)$/', $file, $match); debug($match); list($full, $folder, $filename, $basename, $full_extension, $extension) = $match; return array( "full" => $full, "folder" => $folder, "filename" => $filename, "basename" => $basename, "full_extension" => $full_extension, "extension" => $extension ); }

« previous php.notes (#120690) next »