Function to build a query string

This is probably the most simple case of using http_build_query to build a query string. I'd say this is the best way to build a query string because you don't have to worry about whether or not you put an ampersand before appending a new variable and other cases like that. All you have to do is ensure your array is correct.

<?php
$data = array('foo'=>'bar',
              'baz'=>'boom',
              'cow'=>'milk',
              'php'=>'hypertext processor');

echo http_build_query($data); // foo=bar&baz=boom&cow=milk&php=hypertext+processor
echo http_build_query($data, '', '& amp;'); // foo=bar&baz=boom&cow=milk&php=hypertext+processor
?>

http://www.php.net/http_build_query »

Page Comments (Click to edit)

Design by N.Design Studio, adapted by solidGone.org (version 1.0.0)
Powered by pmwiki-2.2.0-beta65