Reputation: 14575
I was wondering how can I grab the last value in a url for example how can I grab the value someone
in the url below using PHP. Can someone help me do this?
http://www.example.com/questions/ask/someone
Upvotes: 0
Views: 761
Reputation: 5561
search the position of Last slash then make a new substring from the index position of slash to end.It's as simple.
Upvotes: -1
Reputation: 57207
Not too hard:
echo basename($url);
As a side note, you can also use dirname
to get the remainder of the content.
$url = "http://www.example.com/questions/ask/someone";
echo basename($url); // someone
echo dirname($url); // http://www.example.com/questions/ask
Upvotes: 5