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

Reply via email to