Skip to content

Instantly share code, notes, and snippets.

@demaisj
Created August 1, 2014 12:46
Show Gist options
  • Save demaisj/0d59f301f40b0e321cb7 to your computer and use it in GitHub Desktop.
Save demaisj/0d59f301f40b0e321cb7 to your computer and use it in GitHub Desktop.
Builds an URL with GET params in PHP
<?php
/**
* Build an URL with GET params
* @param string $url The URL
* @param array $params The GET params to append to the url
* @return string The new builded URL
*/
function build_get_url($url, $params){
$index = 0;
foreach ($params as $key => $value) {
$delemiter = "&";
if($index == 0){
$delemiter = "?";
}
$url .= $delemiter.$key."=".urlencode($value);
$index++;
}
return $url;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment