Solved

How to trim a string to leave only the image name

Posted on 2003-10-24
7
205 Views
Last Modified: 2006-11-17
I am parsing the following string from a previous page using POST .

folder/subfolder/images/imagename.jpg

to create a link to the image.

I also need to display on the page only the imagename.

How can I remove everything before the imagename and the .jpg file extention?
0
Comment
Question by:coddie
  • 4
  • 3
7 Comments
 
LVL 11

Accepted Solution

by:
shmert earned 50 total points
ID: 9618149
Use basename($path) to get the last path component.
0
 

Author Comment

by:coddie
ID: 9618172
Hi shmert,
Thanks for a prompt reply.
sorry I am a newbie to PHP I dont understand comment, can you expand a little more.
0
 

Author Comment

by:coddie
ID: 9618222
Sorted ......
Thanks for the pointer shmert, It works a treat, the points are yours, one more quick related question - some image names have a 2 word title,ie "so big.jpg" this returns as "so%20big" how can I remove the %20 ?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:coddie
ID: 9618286
Ok .... solved it, I had left the %20 in the parsed URL from the previous page. doh !! ;-)

All works as I want, many thanks shmert

here's 50 points.
0
 
LVL 11

Expert Comment

by:shmert
ID: 9621666
Thanks, coddie.  You may also be interested in urlencode() and urldecode() respectively, for encoding spaces and special characters for urls.

Cheers,
Sam
0
 

Author Comment

by:coddie
ID: 9622050
Cheers Sam,
Thanks for the advice, since my first enquiry and your reply, I have got 'right into' what one can do with strings ..... !

As a ASP coder, I didn't realise there were so many operations that one could perform on a string in PHP.

Learn something new everyday.

All the best

Coddie
0
 
LVL 11

Expert Comment

by:shmert
ID: 9627554
Yes, it seems there are almost too many sometimes.  My biggest gripe is that the arguments to all the string operators aren't always consistent.  Check the manual regularly :-)
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now