PHP/Development/Query String
A Function to Build Query Strings
<html>
<head>
<title>A function to build query strings</title>
</head>
<body>
<?php
function qlink( $q ){
GLOBAL $QUERY_STRING;
if ( ! $q )
return $QUERY_STRING;
$ret = "";
foreach( $q as $key => $val ) {
if ( strlen( $ret ) )
$ret .= "&";
$ret .= urlencode( $key ) . "=" . urlencode( $val );
}
return $ret;
}
$q = array ( name => "Joe",
interest => "coding",
homepage => "http://www.google.ru"
);
print qlink( $q );
?>
<p>
<a href="anotherpage.php?<? print qlink($q) ?>">Go!</a>
</p>
</body>
</html>
Get query string
// http://www.myhost.ru/test.php?aaa+bbb+ccc+ddd
<?
echo "The command line data: $QUERY_STRING";
?>
Send data without a form
<!-- http://127.0.0.1/phab/ph02/hiUser.php?userName=Andy
-->
<html>
<head>
<title>Hi User</title>
</head>
<body>
<h1>Hi User</h1>
<h3>PHP program that receives a value from "whatsName"</h3>
<?
print "<h3>Hi there, $userName!</h3>";
?>
</body>
</html>