Created
January 10, 2022 12:14
-
-
Save stoll/4d82a2b368e1f74963982918654a8469 to your computer and use it in GitHub Desktop.
parse_url_reverse.php
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
function parse_url_reverse(array $parts) | |
{ | |
$scheme = isset($parts['scheme']) ? ($parts['scheme'] . '://') : ''; | |
$host = $parts['host'] ?? ''; | |
$port = isset($parts['port']) ? (':' . $parts['port']) : ''; | |
$user = $parts['user'] ?? ''; | |
$pass = isset($parts['pass']) ? (':' . $parts['pass']) : ''; | |
$pass = ($user || $pass) ? ($pass . '@') : ''; | |
$path = $parts['path'] ?? ''; | |
$query = empty($parts['query']) ? '' : ('?' . $parts['query']); | |
$fragment = empty($parts['fragment']) ? '' : ('#' . $parts['fragment']); | |
return implode('', [$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