references:joomla.framework:environment:juri-buildqueryTable of Contents
buildQuery
Build a query from a array ( Syntaxstring function buildQuery ($params, $akey = null)
The current implementation is not capable to handle complex, nested arrays. The ampersand character (&) is used as the argument separator. The value of the arg_separator.output directive of PHP.INI is ignored. Only array values are urlencode()d, array keys remain unchanged. ExamplesExample 1: simple array $params = array('foo'=>'bar', 'name'=>'Jane Doe'); $str = JURI::buildQuery( $params ); echo $str; will produce: Result 2 foo=bar&name=Jane+Doe Example 2: complex array // a weired looking, but valid URL $url = "foo=bar&bar[baz][bat]=hello&one[]=1&one[]=2"; // parse to array using PHP $params = array(); parse_str( $url, $params ); // recreate URL from $params $str = JURI::buildQuery( $params ); parse_str( $str, $params ); echo 'Original: ', $url, PHP_EOL, print_r($arr, 1); echo 'rebuilt : ', $str, PHP_EOL, print_r($params, 1); will produce: <code php|Result 2> Original: foo=bar&bar[baz][bat]=hello&one[]=1&one[]=2 Array ( [foo] => bar
[bar] => Array
(
[baz] => Array
(
[bat] => hello
)
)
[one] => Array
(
[0] => 1
[1] => 2
)
) rebuilt: foo=bar&baz[]=hello&one[]=1&one[]=2 Array ( [foo] => bar
[bar] => Array
(
[0] => hello
)
[one] => Array
(
[0] => 1
[1] => 2
)
) Discussion |


