You are here: Re: [PHP] convert array to HTML GET request « PHP « IT news, forums, messages
Re: [PHP] convert array to HTML GET request

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.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация