Last active
July 6, 2019 20:24
-
-
Save gollum23/0b861de47ced51f8a50e to your computer and use it in GitHub Desktop.
Get last part URL with php
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
function uf_getLastDir($sUrl) | |
{ | |
$sPath = parse_url($sUrl, PHP_URL_PATH); // parse URL and return only path component | |
$aPath = explode('/', trim($sPath, '/')); // remove surrounding "/" and return parts into array | |
end($aPath); // last element of array | |
if (is_dir($sPath)) // if path points to dir | |
return current($aPath); // return last element of array | |
if (is_file($sPath)) // if path points to file | |
return prev($aPath); // return second to last element of array | |
return false; // or return false | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment