Similar to this question: How to get the last path in a URL?
...Except instead of returning only the last path in the URL, I want to return the last four:
<?php
$url = 'http://blogs.mydomain.com/blog-name/2012/04/21/title-of-the-blog-post';
print_r(parse_url($url));
$url_path = parse_url($url, PHP_URL_PATH);
$parts = explode('/', $url_path);
$relative_permalink = end($parts);
echo $relative_permalink;
?>
The code above is from the earlier Stack Overflow item I linked to. It kind of does what I want, except it returns only title-of-blog-post; I want to return everything after /blog-name/, like this:
/20120/04/21/title-of-blog-post
This code also sort of gets me there:
$url_endpoint = http://blogs.mydomain.com/blog-name/2012/04/21/title-of-the-blog-post;
$url_endpoint = parse_url( $url_endpoint );
$url_endpoint = $url_endpoint['path'];
Except that it also returns /blog-name/ and everything after it. I want to exclude /blog-name/
Any ideas for how I can manipulate either of these snippets?