Created
December 11, 2012 18:54
-
-
Save tylerreed/4261015 to your computer and use it in GitHub Desktop.
Build a Request URL from an Array
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 | |
/* Example of $url and $params */ | |
$url = 'http://api.host.com/'; | |
$params['key1'] = 'value1'; | |
$params['key2'] = 'value2'; | |
/* --------------------------- */ | |
function buildRequestURL( $url, $params ) { | |
$request_url = $url . '?'; | |
$i = 0; | |
foreach ( $params as $param => $value ) { | |
if( $i > 0 ) { | |
$request_url .= '&'; | |
} | |
$request_url .= $param . '=' . urlencode( $value ); | |
$i++; | |
} | |
return $request_url; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment