Skip to content

Commit 6cc6a0d

Browse files
committed
use http_build_query() in buildURLparams()
buildURLparams() is used all throughout the code, but its implementation was overly simplistic. This changes it to use the much better builtin http_build_query() function. This allows for correct encoding of array values or deeper nested structures.
1 parent dbc152d commit 6cc6a0d

File tree

1 file changed

+3
-12
lines changed

1 file changed

+3
-12
lines changed

inc/common.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -346,24 +346,15 @@ function mediainfo()
346346
/**
347347
* Build an string of URL parameters
348348
*
349-
* @param array $params array with key-value pairs
349+
* @see http_build_query()
350+
* @param array|object $params the data to encode
350351
* @param string $sep series of pairs are separated by this character
351352
* @return string query string
352-
* @author Andreas Gohr
353353
*
354354
*/
355355
function buildURLparams($params, $sep = '&')
356356
{
357-
$url = '';
358-
$amp = false;
359-
foreach ($params as $key => $val) {
360-
if ($amp) $url .= $sep;
361-
362-
$url .= rawurlencode($key) . '=';
363-
$url .= rawurlencode((string)$val);
364-
$amp = true;
365-
}
366-
return $url;
357+
return http_build_query($params, '', $sep, PHP_QUERY_RFC3986);
367358
}
368359

369360
/**

0 commit comments

Comments
 (0)