note 82232 added to function.substr

From: Date: Wed, 02 Apr 2008 06:34:11 +0000
Subject: note 82232 added to function.substr
Groups: php.notes 
Request: Send a blank email to php-notes+get-137842@lists.php.net to get a copy of this message
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". ---- Server IP: 209.41.74.194 Probable Submitter: 24.9.128.209 ---- Manual Page -- http://www.php.net/manual/en/function.substr.php Edit -- https://master.php.net/note/edit/82232 Del: integrated -- https://master.php.net/note/delete/82232/integrated Del: useless -- https://master.php.net/note/delete/82232/useless Del: bad code -- https://master.php.net/note/delete/82232/bad+code Del: spam -- https://master.php.net/note/delete/82232/spam Del: non-english -- https://master.php.net/note/delete/82232/non-english Del: in docs -- https://master.php.net/note/delete/82232/in+docs Del: other reasons-- https://master.php.net/note/delete/82232 Reject -- https://master.php.net/note/reject/82232 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#137842) next »