Php Snippet: Parse Url and Separate All It'S Parts

by admin admin Date: 11-04-2013


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;
 
by admin admin Date: 11-04-2013 hits : 1461