taking off an extention from an array

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
quietk
Forum Newbie
Posts: 7
Joined: Sun Nov 16, 2003 10:33 pm
Location: California

taking off an extention from an array

Post 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
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

Code: Select all

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

you could also use strrpos() w/ substr()
printf
Forum Contributor
Posts: 173
Joined: Wed Jan 12, 2005 5:24 pm

Post 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
quietk
Forum Newbie
Posts: 7
Joined: Sun Nov 16, 2003 10:33 pm
Location: California

Post by quietk »

thanks printf that worked.
Post Reply