Solved

How to trim a string to leave only the image name

Posted on 2003-10-24
7
207 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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 …
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

829 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