note 55584 deleted from function.http-build-query by nlopess

From: Date: Sat, 12 Aug 2006 18:21:12 +0000
Subject: note 55584 deleted from function.http-build-query by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-115838@lists.php.net to get a copy of this message
Note Submitter: mwwaygoo AT hotmail DOT com ---- 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; } } ?>

« previous php.notes (#115838) next »