Reputation: 49384
How do I get the last word in a url between / and /
For example:
http://mywebsite.com/extractMe/
I want to get "extractMe" (without the quotes) from the url
NOTE: I need to get the "extractMe" equivilent of the current url.
Upvotes: 0
Views: 1814
Reputation: 58531
With regex you can match this pattern, or many other more intricate patterns:
echo preg_replace('/.*\/(.+?)\/$/','$1',$url);
Upvotes: 1
Reputation: 816404
In case you want to get the full path, you can use parse_url
:
$path = trim(parse_url($url, PHP_URL_PATH), '/');
Upvotes: 0
Reputation: 5084
I prefer to use basename() in these circumstances as it's more implicit.
echo basename('http://mywebsite.com/extractMe/'); //extractMe
Upvotes: 8