Last active
December 20, 2015 05:28
-
-
Save DaveRandom/6078005 to your computer and use it in GitHub Desktop.
PHP build_url()
This file contains 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 | |
function build_url($parts) | |
{ | |
$result = ''; | |
if (isset($parts['scheme'])) { | |
$result .= $parts['scheme'] . ':'; | |
} | |
if (isset($parts['host'])) { | |
$result .= '//'; | |
if (isset($parts['user'])) { | |
$result .= $parts['user']; | |
if (isset($parts['pass'])) { | |
$result .= ':' . $parts['pass']; | |
} | |
$result .= '@'; | |
} | |
$result .= $parts['host']; | |
if (isset($parts['port'])) { | |
$result .= ':' . $parts['port']; | |
} | |
} | |
if (isset($parts['path'])) { | |
$result .= $parts['path']; | |
} | |
if (isset($parts['query'])) { | |
$result .= '?' . $parts['query']; | |
} | |
if (isset($parts['fragment'])) { | |
$result .= '#' . $parts['fragment']; | |
} | |
return $result !== '' ? $result : false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment