Re: separating strings from extensions

From: Date: Sun, 17 Feb 2008 23:29:35 +0000
Subject: Re: separating strings from extensions
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-269455@lists.php.net to get a copy of this message
Børge Holen wrote:
On Monday 18 February 2008 00:10:30 John Meyer wrote:
Daniel Brown wrote:
    
On Feb 17, 2008 5:37 PM, nihilism machine <nihilismmachine@gmail.com>
wrote:
i am using this code to get the extension of a filename: $extension = strtolower(strrchr($fileName,".")); how can i get the text BEFORE the . (period)
        
You can STFW and RTFM. This list should never be your first place to ask simple questions.
    In any case....
<? $split = explode('.',strtolower($fileName)); $name = $split[0]; $ext = $split[1]; ?>
      
Flame job aside, that's going to fail on a compound extension such as ".tar.gz" by just returning .tar
    
so. it.will.fail.this.one.to.txt and a fix would also fail because you would have to hardcord everygoddamn ending if thats what youre after. How many do you care to count for? I would say stick with the last dot, if its not particulary often you stumble over those .tar.bz2 endings.
You could also stick with the first, i.e.: <? $split = explode('.',strtolower($fileName),1); $name = $split[0]; $ext = $split[1]; ?>

« previous php.general (#269455) next »