<?php // To build back the URI and to extract the passed parameters, you can use parse_url, parse_string function $extract_string = parse_url($pass_string); echo "<h2>Extracted URI (using parse_url)</h2><br />"; echo "<pre>"; var_dump($extract_string); echo "</pre>"; // To decode the query string use parse_str function parse_str($extract_string["query"], $extract_query); echo "<h2>Extracted Query String (using parse_str)</h2><br />"; echo "<pre>"; var_dump($extract_query); echo "</pre>"; ?>
<?php
// PHP 5 how to pass data as a query string
/*
http_build_query is a function in PHP 5 that enables you to URL encode the query string. You can pass an array or an array of array to this function. The default separator is "&"
*/
$data = array("first_name" => "Robert",
"last_name" => "Brown",
"address" => "123 Adam St., New York"
);
// URI formatted with character encoding
$pass_string = "http://localhost/demo.php?".http_build_query($data, '');
echo "<h2>Query URI (using http_build_query)</h2><br />";
echo $pass_string;
?>
Ouput from the above execution:
Query URI (using http_build_query)
http://localhost/demo.php?first_name=Robert&last_name=Brown&address=123+Adam+St.%2C+New+York