Reputation: 5238
We have a link like http://stackoverflow.com/questions/9281910/h1-and-semantic-html5
How do I get the part, which is before the last and after last but one /
?
In this example we would get h1-and-semantic-html5
More examples:
From the link http://dribbble.com/highlights/2012/
we get 2012
From http://www.apple.com/iphone/
we get iphone
Upvotes: 0
Views: 174
Reputation: 7834
basename
should provide what you're looking for:
php > echo basename("http://stackoverflow.com/questions/9281910/h1-and-semantic-html5");
h1-and-semantic-html5
php > echo basename("http://dribbble.com/highlights/2012/");
2012
php > echo basename("http://www.apple.com/iphone/");
iphone
Read more about it in the documentation.
Upvotes: 10
Reputation: 15451
$fin = preg_replace('#.*/([^/]+)/?$#', '$1', $whole);
Grab the last portion of non-forward slash characters (potentially followed by a forward slash)
Upvotes: 1