Skip to content

Instantly share code, notes, and snippets.

@DaveRandom
Last active December 20, 2015 05:28
Show Gist options
  • Save DaveRandom/6078005 to your computer and use it in GitHub Desktop.
Save DaveRandom/6078005 to your computer and use it in GitHub Desktop.
PHP build_url()
<?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