?
Solved

How to trim a string to leave only the image name

Posted on 2003-10-24
7
Medium Priority
?
212 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 11

Accepted Solution

by:
shmert earned 200 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

WordPress Tutorial 3: Plugins, Themes, and Widgets

The three most common changes you will make to your website involve the look (themes), the functionality (plugins), and modular elements (widgets).

In this article we will briefly define each again, and give you directions on how to install them.

Question has a verified solution.

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

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…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

770 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