Page 1 of 1

Using File Names

Posted: Wed Oct 16, 2002 5:53 am
by Visual
Hi, Hope someone here can help a newbie :)

I'm trying to code a simple custom image gallery for my site. I'm trying to keep it as simple as possible. What i have is images with names like;

John_and_Jane_at_Ibiza.jpg

How can i take the file name and remove the underscores (_) and file ending (.jpg/.gif) so that i end up with a simple discription of the image which i can put in the page like $title

Thanks

Visual

Posted: Wed Oct 16, 2002 6:01 am
by twigletmac
One way could be to use str_replace():

Code: Select all

$change_to = array(' ', '');
$change_from = array('_', '.gif', '.jpeg', '.jpg');

$image_name = 'John_and_Jane_at_Ibiza.jpg';
$title_text = str_replace($change_from, $change_to, $image_name);
echo $title_text;
Hope it helps,

Mac

Posted: Wed Oct 16, 2002 6:21 am
by Visual
absolutly great m8

thanks a mil


Visual