Thanks!
Getting the position of the last occurrence of a string
Moderator: General Moderators
- evilmonkey
- Forum Regular
- Posts: 823
- Joined: Sun Oct 06, 2002 1:24 pm
- Location: Toronto, Canada
Getting the position of the last occurrence of a string
Is there a way to do that in PHP? For example, path/to/folder/with/an/image.jpg. I only want the image.jpg part. What's the easiest way to do this?
Thanks!
Thanks!
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
I think you can use explode() to split it on the '/' or you can reverse the string and then strpos everything after the '/' then reverse the string back.
Just a thought. I am sure there is an easier way to do it, but I have done this before to get what you are after.
Just a thought. I am sure there is an easier way to do it, but I have done this before to get what you are after.
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Oh crap, forgot to put that one in there. I used to use a combination of substr and strpos to get the name portion of the current script before I read here that you can use basename().
I love these forums!
I love these forums!
- evilmonkey
- Forum Regular
- Posts: 823
- Joined: Sun Oct 06, 2002 1:24 pm
- Location: Toronto, Canada