Use PHP function parse_url to get all components of a URL
<?php
$url="//www.example.com/dir?data=1";
// Prior to 5.4.7 this would show the path as "//www.example.com/path"
var_dump(parse_url($url));
?>
Output:
array(3) {
["host"]=>
string(15) "www.example.com"
["path"]=>
string(4) "/dir"
["query"]=>
string(6) "data=1"
}