Page 1 of 1

taking off an extention from an array

Posted: Wed Jan 12, 2005 5:40 pm
by quietk
I have a gallery and when you click the image it open like this

example.com/gallery.php?show=theimage.jpg

how could i strip the .jpg off when it loads again so its just like

example.com/gallery.php?show=theimage

its a dynamic gallery and builds itself from dir. of images.

Thanks

Posted: Wed Jan 12, 2005 6:31 pm
by rehfeld

Code: Select all

$parts = explode('.', $filename);
echo $partsї0];

you could also use strrpos() w/ substr()

Posted: Wed Jan 12, 2005 6:35 pm
by printf
Hi

If your using PHP scripting then use something like so...

Code: Select all

<?

$url = 'http://example.com/gallery.php?show=theimage.jpg';

echo strip_ext ( $url );


function strip_ext ( $str )
&#123;
	return substr ( $str, 0, strrpos ( $str, '.' ) );
&#125;

?>
Of if your using Apache and want this to be done at the server level, look at mod_rewrite!


printf

Posted: Wed Jan 12, 2005 6:40 pm
by quietk
thanks printf that worked.