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;
 
 


We use our own cookies and third-party cookies to improve our services, show products based on your preferences, analyse the browsing habits of our users, and enable interaction with social networks. Continuing to browse our sites implies full acceptance of their use. You can change your cookie setting or get more information here: Cookies policy .