Jump to content

Remove extencion .zip from filenames


ztealmax

Recommended Posts

Hi how would i remove the extencion .zip when echoing filenames?

 

Using this code:

<?php
  
  $dir = "thisisapath/";
  $dh  = opendir($dir);
  while (false !== ($filename = readdir($dh))) 
{
   $pattern = '/\.zip$/';
   if(preg_match($pattern,$filename))
   {
      /*    You can proceed because the file has the extension .zip       */
echo $filename . "<br>";
   }
}

?>

 

//Cheers :-)

Link to comment
https://forums.phpfreaks.com/topic/56729-remove-extencion-zip-from-filenames/
Share on other sites

Now for an even more stupid question ;)

 

if it echos out dir/filename (.zip extencion now removed using this code)

$filename = ereg_replace(".zip", "", "$filename");

 

Now if i would like to also remove the search path dir/ thats

infront of the filename, how would i do that?

 

//Cheers :D

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.