You need to construct a link that includes name/value pairs in a query string.
Use the http_build_query( ) function, as in Example 8-14.
Building a query string
The URL built in Example 8-14 is:
The query string has spaces encoded as +. Special characters such as # are hex encoded as %23 because the ASCII value of # is 35, which is 23 in hexadecimal.
Although the encoding that http_build_query( ) does prevents any special characters in the variable names or values from disrupting the constructed URL, you may have problems if your variable names begin with the names of HTML entities. Consider this partial URL for retrieving information about a stereo system:
The HTML entity for ampersand (&) is & so a browser may interpret that URL as:
To prevent embedded entities from corrupting your URLs, you have three choices. The first is to choose variable names that can't be confused with entities, such as _amp instead of amp. The second is to convert characters with HTML entity equivalents to those entities before printing out the URL. Use htmlentities( ):
$url = '/muppet/select.php?' . htmlentities($query_string);
The resulting URL is:
Your third choice is to change the argument separator from & to & by setting the configuration directive arg_separator.input to &. Then, http_build_query( ) joins the different name=value pairs with &:
8.6.4. See Also
Documentation on http_build_query( ) at http://www.php.net/http_build_query and htmlentities( ) at http://www.php.net/htmlentities.