0

I'm curious as to how I would get a certain value after a delimiter in a URL?

If I have a URL of http://www.testing.site.com/site/biz/i-want-this, how would I extract only the part that says "i-want-this", or initially after the last /?

Thank you!

2 Answers 2

4

You want basename($path); It should give you what you need:

http://www.ideone.com/8hFSN

Sign up to request clarification or add additional context in comments.

1 Comment

Cool, you can approve the answer then.
1
$url = "http://www.testing.site.com/site/biz/i-want-this";
preg_match( "/[^\/]*$/", $url, $match);
echo $match[0];  // i-want-this

You can use basename() but if you are on Windows, it will break on not just slashes but also backslashes. This is unlikely to come up as backslashes are unusual in a URL. But I suspect you could find them in a query string in a valid URL.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.