Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

stripping multiple extensions off filename

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

stripping multiple extensions off filename

Postby quiknot » Thu Apr 24, 2003 11:42 am

Hi, I need to be able to take a filename, say test.tar.gz and rename it to test.tgz. So I would like to be able to strip off the extension(s), check to see if they are .tar.gz, and if they are, create the file test.tgz. Anyone got some code to do this? Tried using the examples under basename at php.net but could not find the right one.

Thanks!
quiknot
New php-forum User
New php-forum User
 
Posts: 2
Joined: Tue Apr 01, 2003 1:01 pm

Postby Oleg Butuzov » Thu Apr 24, 2003 8:48 pm

code for lammers.
here is algoritm

read a file name
brake it is to parts
count all part
make a new file name
rename function
Oleg Butuzov
Last Samuray
Last Samuray
 
Posts: 831
Joined: Sun Jun 02, 2002 3:09 am

Postby pootergeist » Fri Apr 25, 2003 12:37 am

$renamed_file = (substr($file,-7) == '.tar.gz') ? rename($file,substr($file,0,-7).'.tgz') : NULL;

check the numerics on that though.
pootergeist
New php-forum User
New php-forum User
 
Posts: 191
Joined: Wed Jan 29, 2003 7:11 am
Location: UK


Return to PHP coding => General

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.