Skip to content

Instantly share code, notes, and snippets.

@jamesl1001
Created September 18, 2013 16:40
Show Gist options
  • Save jamesl1001/6611889 to your computer and use it in GitHub Desktop.
Save jamesl1001/6611889 to your computer and use it in GitHub Desktop.
Explode uri path ignoring trailing slash
<?php
$url = parse_url($_SERVER["REQUEST_URI"]);
$path = explode("/", trim($url['path'], '/'));
echo (empty($path[count($path)-1]) ? "index" : $path[count($path)-1]);
// Only returns the last part of the path
// e.g. http://domain.co.uk/user/james will only return 'james'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment