Created
September 18, 2013 16:40
-
-
Save jamesl1001/6611889 to your computer and use it in GitHub Desktop.
Explode uri path ignoring trailing slash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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