Created
August 1, 2014 12:46
-
-
Save demaisj/0d59f301f40b0e321cb7 to your computer and use it in GitHub Desktop.
Builds an URL with GET params in 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
<?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