Link to home
Start Free TrialLog in
Avatar of peps03
peps03

asked on

strip directory name and extension from file name

Hi,

I use this script to get pictures from a folder and display them.

I would like to strip the directory-name and the extension from "$num" (IN THE TITLE TAG) so the title will have the picture name only.

thanks a lot!
<?php 
						$files = glob("pictures/*.*"); 
						$files = array_reverse($files); for ($i=0; $i<count($files); $i++) { $num = $files[$i]; 
						echo "<a href='".$num."' rel='shadowbox[Mobile]' title=\"". $num ." | Navigate with the &#8249;&#8212; and &#8212;&#8250; arrowbuttons.\"><img src='imgsize.php?h=75&img=".$num."' style='border: solid 1px black;'></a>&nbsp;&nbsp;";}
						 ?>

Open in new window

Avatar of guitar7man
guitar7man
Flag of United States of America image

Are there further directories within the pictures folder?
This should do the trick:

$path = "/home/httpd/html/index.php";
$file = basename($path);
$file=substr($file,0,strrpos($file,'.'));

echo $file;
Avatar of wuff
wuff

if all files have the same extension, e.g. ".jpg" you can provide this to basename() and you get the filename without extension.

$path = "/mydir/images/myimage.jpg";
$filename = basename($path, '.jpg');
echo $filename;

gives this output:

myimage
Avatar of peps03

ASKER

thanks ziceva, but i dont really get it.

how do i fit that in the code above? --> title=\"". $num ."

the num has to be stripped from dir-name and .jpg

@quitar7man: no

thanks!
ASKER CERTIFIED SOLUTION
Avatar of ziceva
ziceva
Flag of Romania image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of peps03

ASKER

Thanks a lot Ziceva!

It works great!