Php Snippet: parse url and separate all it's parts

Php Snippet: parse url and separate all it's parts

Use this snippet to get some value iside urls, for example the last directory.

$url = 'https://aplicaciones.org/wp-content/uploads/2011/09/skypevideo-500x361.jpg?arg=value#anchor';

print_r(parse_url($url));

$url_path = parse_url($url, PHP_URL_PATH);
$parts = explode('/', $url_path);
$last = end($parts);

echo $last;