How to strip the extensions Example In directory Dir1 are the next files: Dir2 Image.jpg file.txt index.html
the scripts prints:
image.jpg file.txt
and i want it to print image file
Can someone code that for me in this coding?
<? $extensions = "(html|htm)"; $handle = @opendir($txts); while (false !== ($file = readdir($handle))){ if ($file != "." && $file != ".." && (ereg($extensions, $file) <> 1) && !is_dir($file)) { echo '<tr><td height="15"><a href=" ' . $file . ' " > '.$file.'</a></td></tr>'; } } closedir($handle); ?>
Try this:
<? $extensions = "(html|htm)"; $handle = @opendir($txts); while (false !== ($file = readdir($handle))) { if ($file != "." && $file != ".." && (ereg($extensions, $file) <> 1) && !is_dir($file)) { $ext = explode(".",$file); echo '<tr><td height="15"><a href=" ' . $file . ' " > '.$ext[0].'</a></td></tr>'; } } closedir($handle); ?>
Tnx that worked!
you're welcome!
What if your file is something like "a.filename.with.points.in.it" ??? It will only print "a"... not really efficient !!
That's simply ! Invert the string, find the first point, remove all between the start and the point, then invert again.. !
oops... didn't think of that... :o
Heres a post at Tutorialforums that might help you http://tutorialforums.com/showthread.php?s=&threadid=27172
how do you invert a filename or a string?
Use strrev($string) where $string is the string to reverse...
I mean, you're not using the extension or anything, so why go to the trouble of keeping it?
$shortened_name = substr($name, 0, strrpos($name, '.')); $name = 'log.2002.11.28.html'; echo substr($name,0,strrpos($name,'.'));
Originally posted by suntra What if your file is something like "a.filename.with.points.in.it" ??? It will only print "a"... not really efficient !! That's simply ! Invert the string, find the first point, remove all between the start and the point, then invert again.. !
Well i have no idee how to do that then? Can you or somebody code that for me within this.
Yes i'm a Newbee Yes i've know www.php.net
Originally posted by stefandv Well i have no idee how to do that then?
Read some of the previous posts. Apply a bit of thought.
Advice i took.. People can help you here only so much.. But Server Side Languages can be coded so differently.. Like 1 person may do the same thing as you and can do it differently..
Ok in the meaning of that.. Try what people give.. Then experiment on your own.. Who knows you may start to learn🙂