stripping multiple extensions off filename

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

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

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 but could not find the right one.


User avatar
Oleg Butuzov
Last Samuray
Last Samuray
Posts: 831
Joined: Sun Jun 02, 2002 3:09 am

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

User avatar
New php-forum User
New php-forum User
Posts: 191
Joined: Wed Jan 29, 2003 7:11 am
Location: UK

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.

Return to “PHP coding => General”

Who is online

Users browsing this forum: Yahoo [Bot] and 5 guests