|
Posted by "M. Sokolewicz" on 10/02/05 23:50
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.
[Back to original message]
|