note 16542 added to function.urlencode
| From: | xs0 at php2 dot chek dot com | Date: | Sat, 03 Nov 2001 14:43:28 +0000 |
| Subject: | note 16542 added to function.urlencode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-20360@lists.php.net to get a copy of this message | ||
if you need to pass an array variable or an array of variables, you can use the function below.
Examples:
<?
header("Location: http://example.com/something.php?" .
myurlencode($HTTP_POST_VARS));
?>
or
<?
$vars=array("blah"=>array(1,2,3));
echo '<a href="something.php?'.myurlencode($vars).'">Click
here</a>';
// output: <a href="something.php?blah[0]=1&blah[1]=2&blah[2]=3">Click
here</a>
?>
----
function myurlencode($a)
{
$out="";
$queue=array();
foreach($a as $key=>$val) {
if (!is_array($val)) {
if (strlen($out)) $out.="&";
$out.=urlencode($key);
$out.="=";
$out.=urlencode($val);
} else {
$queue[]=array($key, $val);
}
}
while (sizeof($queue)) {
list($key,$val)=array_shift($queue);
foreach($val as $field => $fvalue) {
if (is_array($fvalue)) {
$queue[]=array($key."[".$field."]", $fvalue);
} else {
if (strlen($out)) $out.="&";
$out.=$key."[".$field."]=".urlencode($fvalue);
}
}
}
return $out;
}
--
http://www.php.net/manual/en/function.urlencode.php
http://master.php.net/manage/user-notes.php?action=edit+16542
http://master.php.net/manage/user-notes.php?action=delete+16542
http://master.php.net/manage/user-notes.php?action=reject+16542