From e2ea803dbd17989fd698add2ec7c6088557e4cd3 Mon Sep 17 00:00:00 2001 From: Sara Golemon Date: Wed, 10 Sep 2003 15:35:59 +0000 Subject: [PATCH] Initial Revision git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@140019 c90b9560-bf6c-de11-be94-00142212c4b1 --- reference/url/functions/http-build-query.xml | 153 +++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 reference/url/functions/http-build-query.xml diff --git a/reference/url/functions/http-build-query.xml b/reference/url/functions/http-build-query.xml new file mode 100644 index 0000000000..d9e51b42db --- /dev/null +++ b/reference/url/functions/http-build-query.xml @@ -0,0 +1,153 @@ + + + + + http_build_query + Generate url-encoded query string + + + Description + + stringhttp_build_query + arrayformdata + stringnumeric_prefix + + + + Generates a url-encoded query string from the associative (or indexed) array provided. + formdata may be an array or object containing properties. + A formdata array may be a simple one-dimensional structure, + or an array of arrays (who in turn may contain other arrays). If numeric indices + are used in the base array and a numeric_prefix is provided, + it will be prepended to the numeric index for elements in the base array only. + This is to allow for legal variable names when the data is decoded by PHP + or another CGI application later on. + + + + Simple usage of <function>http_build_query</function> + +'bar', + 'baz'=>'boom', + 'cow'=>'milk', + 'php'=>'hypertext processor'); + +echo http_build_query($data); +/* Outputs: + foo=bar&baz=boom&cow=milk&php=hypertext+processor + */ +?> +]]> + + + + + <function>http_build_query</function> with numerically index elements. + + 'milk', 'php' =>'hypertext processor'); + +echo http_build_query($data); +/* Outputs: + 0=foo&1=bar&2=baz&3=boom&cow=milk&php=hypertext+processor + */ + +echo http_build_query($data, 'myvar_'); +/* Outputs: + myvar_0=foo&myvar_1=bar&myvar_2=baz&myvar_3=boom&cow=milk&php=hypertext+processor + */ +?> +]]> + + + + + <function>http_build_query</function> with complex arrays + +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_'); +/* Outputs: (word wrapped for readability) + user[name]=Bob+Smith&user[age]=47&user[sex]=M&user[dob]=5%1F12%1F1956& + pastimes[0]=golf&pastimes[1]=opera&pastimes[2]=poker&pastimes[3]=rap& + children[bobby][age]=12&children[bobby][sex]=M&children[sally][age]=8& + children[sally][sex]=F&flags_0=CEO + + Note: Only the numericly indexed element in the base array "CEO" + received a prefix. The other numeric indices, found under + pastimes, do not require a string prefix to be legal variable names. + */ +?> +]]> + + + + + Using <function>http_build_query</function> with an object + +foo = 'bar'; + $this->baz = 'boom'; + } +} + +$data = new myClass(); + +echo http_build_query($data); +/* Outputs: + foo=bar&baz=boom + */ +?> +]]> + + + + + See also: + urlencode, and + array_walk + + + + + +