note 44713 deleted from function.http-build-query by tomsommer
| From: | tomsommer@php.net | Date: | Sat, 14 Aug 2004 01:54:47 +0000 |
| Subject: | note 44713 deleted from function.http-build-query by tomsommer | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-74606@lists.php.net to get a copy of this message | ||
Note Submitter:
----
Antoher gottcha. "&" is not allways used to separate the arguments. Such as in XHTML
when & is used. Use ini_get("arg_separator.output") to obtain the current
separator.
<?php
if (!function_exists('http_build_query')){function
http_build_query(&$a,$pref,$f='',$idx='')
{
$ret = '';
foreach ($a as $i => $j)
{
if ($idx != '')
$i = $idx."[$i]";
if (is_array($j))
$ret .= http_build_query($j,'',$f,$i);
else
{
$j=urlencode($j);
if (is_int($i))
$ret .= "$f$pref$i=$j";
else
$ret .= "$f$i=$j";
}
$f=ini_get("arg_separator.output");
}
return $ret;
}}
$data = array('user'=>array('name'=>'Bob Smith',
'age'=>47,
'sex'=>'M',
'dob'=>'5/12/1956'),
'pastimes'=>array('golf', 'opera', 'poker',
'rap'),
'children'=>array('bobby'=>array('age'=>12,
'sex'=>'M'),
'sally'=>array('age'=>8,
'sex'=>'F')),
'CEO');
echo http_build_query($data, 'flags_');
?>