note 55584 added to function.http-build-query
| From: | mwwaygooAThotmailDOTcom at osu1 dot php dot net | Date: | Mon, 08 Aug 2005 08:25:34 +0000 |
| Subject: | note 55584 added to function.http-build-query | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-93234@lists.php.net to get a copy of this message | ||
The example given below works great but not for complex arrays. So I wrote one that did :)
The 3rd and 4th parameters are used to contruct the query from the complex array, so dont use them
yourself, just stick to the defined variables as defined above.
<?php
if(!defined('http_build_query'))
{
function http_build_query($array, $flags='', $flags_unchecked=TRUE, $index="")
{
if($flags_unchecked)
{
if(is_string($flags))
{
$flags = ereg_replace("[^a-z0-9_]", "", $flags);
}
else
{
$flags = '';
}
}
$string = "";
if(is_array($array))
{
foreach($array as $name => $value)
{
if(is_array($value))
{
if($index=="")
{
$string.=http_build_query($value, $flags, FALSE, $name);
}
else
{
$string.=http_build_query($value, $flags, FALSE, $index."[".$name."]");
}
}
else
{
if($index=="")
{
if(is_int($name))
{
$name=$flags.$name;
}
$string .= $name . "=" . urlencode($value) . "&";
}
else
{
$string .= $index . "[" . $name . "]=" . urlencode($value) .
"&";
}
}
}
if($index=="")
{
$string=ereg_replace("&$","",$string);
}
}
return $string;
}
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.http-build-query.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+55584
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+55584&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+55584&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+55584&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+55584&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+55584&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+55584&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+55584&report=yes
Search -- http://master.php.net/manage/user-notes.php