note 44713 added to function.http-build-query
| From: | php-general at lists dot php dot net | Date: | Sat, 14 Aug 2004 00:03:01 +0000 |
| Subject: | note 44713 added to function.http-build-query | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-74598@lists.php.net to get a copy of this message | ||
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_');
?>
----
Manual Page -- http://www.php.net/manual/en/function.http-build-query.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+44713
Delete -- http://master.php.net/manage/user-notes.php?action=delete+44713&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+44713&report=yes
Search -- http://master.php.net/manage/user-notes.php