Using File Names

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
Visual
Forum Newbie
Posts: 4
Joined: Wed Oct 16, 2002 5:53 am

Using File Names

Post 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
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
Visual
Forum Newbie
Posts: 4
Joined: Wed Oct 16, 2002 5:53 am

Post by Visual »

absolutly great m8

thanks a mil


Visual
Post Reply