Re: [PHP] convert array to HTML GET request
on 2nd page you can use global $HTTP_POST_VARS; print_r($HTTP_POST_VARS); /// u can use $HTTP_GET_VARS for GET method regards hope adriano ghezzi wrote: if i understand well you need to get an array from html post if you use the same name for your html fields you automatically have an array in $_POST eg input type=text name=myfield value=field_1 input type=text name=myfield value=field_2 you'll get the array ar_myfield = $_POS['myfield'] you should achieve the same result using myfield[key] in the name of html hyh by ag. 2005/10/2, Martin van den Berg [EMAIL PROTECTED]: Newbe question: How does one convert an array into a HTML GET request easely? Are there any standard functions? Same for HTML POST requests. Thanks, Martin. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] convert array to HTML GET request
Newbe question: How does one convert an array into a HTML GET request easely? Are there any standard functions? Same for HTML POST requests. Thanks, Martin. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] convert array to HTML GET request
Martin van den Berg wrote: How does one convert an array into a HTML GET request easely? Are there any standard functions? Same for HTML POST requests. HTTP GET and POST requests are formatted the same, just sent in different ways. I don't know if there's a function; I'd just use: ?php $myArray = array( 'apples' = 'oranges', 'pears' = 'peaches', ); $queryParts = array(); foreach( $myArray as $key=$value ) { $queryParts[] = $key=$value; } $query = implode( '', $queryParts ); // For GET, use e.g.: $data = file_get_contents( http://www.example.com/?$query; ); // For POST, pass $query to curl_setopt for an HTTP POST (see CURL docs) ? Disclaimer: I typed this from memory and haven't tested it, so there might be minor errors, but you get the picture. -- Jasper Bryant-Greene Freelance web developer http://jasper.bryant-greene.name/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] convert array to HTML GET request
Jasper Bryant-Greene wrote: Martin van den Berg wrote: How does one convert an array into a HTML GET request easely? Are there any standard functions? Same for HTML POST requests. HTTP GET and POST requests are formatted the same, just sent in different ways. I don't know if there's a function; I'd just use: ?php $myArray = array( 'apples' = 'oranges', 'pears' = 'peaches', ); $queryParts = array(); foreach( $myArray as $key=$value ) { $queryParts[] = $key=$value; you might also want to use urlencode() in here to make sure the URL stays valid. - tul } $query = implode( '', $queryParts ); // For GET, use e.g.: $data = file_get_contents( http://www.example.com/?$query; ); // For POST, pass $query to curl_setopt for an HTTP POST (see CURL docs) ? Disclaimer: I typed this from memory and haven't tested it, so there might be minor errors, but you get the picture. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] convert array to HTML GET request
PHP 5 has the http_build_query function which does exactly what you want: http://www.php.net/http_build_query Chris Martin van den Berg wrote: Newbe question: How does one convert an array into a HTML GET request easely? Are there any standard functions? Same for HTML POST requests. Thanks, Martin. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] convert array to HTML GET request
if i understand well you need to get an array from html post if you use the same name for your html fields you automatically have an array in $_POST eg input type=text name=myfield value=field_1 input type=text name=myfield value=field_2 you'll get the array ar_myfield = $_POS['myfield'] you should achieve the same result using myfield[key] in the name of html hyh by ag. 2005/10/2, Martin van den Berg [EMAIL PROTECTED]: Newbe question: How does one convert an array into a HTML GET request easely? Are there any standard functions? Same for HTML POST requests. Thanks, Martin. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php