Skip to content

Instantly share code, notes, and snippets.

@stoll
Created January 10, 2022 12:14
Show Gist options
  • Save stoll/4d82a2b368e1f74963982918654a8469 to your computer and use it in GitHub Desktop.
Save stoll/4d82a2b368e1f74963982918654a8469 to your computer and use it in GitHub Desktop.
parse_url_reverse.php
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