Sunday, May 26, 2013

Generate URL-encoded query string (http_build_query) :



If you passed associative array and return result is query string with encoded.

Code:

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

echo http_build_query($data) . "\n";
echo http_build_query($data'''&amp;');

?>

OutPut:

foo=bar&baz=boom&cow=milk&php=hypertext+processor
foo=bar&amp;baz=boom&amp;cow=milk&amp;php=hypertext+processor

 


No comments:

Post a Comment