-
-
Save saber13812002/5c018925254d48ebdbc1be406ba1c91a to your computer and use it in GitHub Desktop.
Parse url. Break down a url to get the parameters / arguments. Very helpful....
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$url = 'http://usr:[email protected]:81/mypath/myfile.html?a=b&b[]=2&b[]=3#myfragment'; | |
if ($url === unparse_url(parse_url($url))) { | |
print "YES, they match!\n"; | |
} | |
function unparse_url($parsed_url) { | |
$scheme = isset($parsed_url['scheme']) ? $parsed_url['scheme'] . '://' : ''; | |
$host = isset($parsed_url['host']) ? $parsed_url['host'] : ''; | |
$port = isset($parsed_url['port']) ? ':' . $parsed_url['port'] : ''; | |
$user = isset($parsed_url['user']) ? $parsed_url['user'] : ''; | |
$pass = isset($parsed_url['pass']) ? ':' . $parsed_url['pass'] : ''; | |
$pass = ($user || $pass) ? "$pass@" : ''; | |
$path = isset($parsed_url['path']) ? $parsed_url['path'] : ''; | |
$query = isset($parsed_url['query']) ? '?' . $parsed_url['query'] : ''; | |
$fragment = isset($parsed_url['fragment']) ? '#' . $parsed_url['fragment'] : ''; | |
return "$scheme$user$pass$host$port$path$query$fragment"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment