How to trim a string to leave only the image name

I am parsing the following string from a previous page using POST .


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?
Who is Participating?
shmertConnect With a Mentor Commented:
Use basename($path) to get the last path component.
coddieAuthor Commented:
Hi shmert,
Thanks for a prompt reply.
sorry I am a newbie to PHP I dont understand comment, can you expand a little more.
coddieAuthor Commented:
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 ?
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

coddieAuthor Commented:
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.
Thanks, coddie.  You may also be interested in urlencode() and urldecode() respectively, for encoding spaces and special characters for urls.

coddieAuthor Commented:
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

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 :-)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.