You can also use parse_url() function from Locutus project (former php.js).
Code:
parse_url('http://username:password@hostname/path?arg=value#anchor');
Result:
{
scheme: 'http',
host: 'hostname',
user: 'username',
pass: 'password',
path: '/path',
query: 'arg=value',
fragment: 'anchor'
}