deleting file extensions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
decoy1
Forum Commoner
Posts: 50
Joined: Fri Feb 21, 2003 1:33 pm
Location: St. Louis

deleting file extensions

Post by decoy1 »

Hi,

Could anyone show me how to delete the extension off a file? This is the little bit I have now...

Code: Select all

while(false !== ($file = readdir($dir)))
{
  $sep = explode('.', $file);
  //$num = count($sep);
  //$ext = $split[$num - 1];
  foreach($sep as $key => $value)
  {
    echo $value. '<br>';
  }
}
As you can see, I can blow the file name up and isolate the extension but not sure what to do next. I can't believe I'm not thinking of a way to do it. Am I approaching this correctly, or should I be using some sort of regular expression, or what? Thanks in advance for any advice.

Rob
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Do you mean you are displaying the file and you wish to hide the file extensions? OR do you mean actually delete the extensions ( dont see the point in this )

If it is the first one, why dont you try looking 1 sec in the forums and check out this thread

viewtopic.php?t=17664
decoy1
Forum Commoner
Posts: 50
Joined: Fri Feb 21, 2003 1:33 pm
Location: St. Louis

Post by decoy1 »

Hi,

sorry...it isn't necessary to actually delete them, just not display them.

thanks
decoy1
Forum Commoner
Posts: 50
Joined: Fri Feb 21, 2003 1:33 pm
Location: St. Louis

Post by decoy1 »

I just now saw your link to the other thread... I just needed someone to smack me in the back of the head and wake me up.

Appreciate the help
Post Reply