My question is related to this one. except that my question is more sepcific as it is about whether a hyphen can be used in a query string parameter value.
I am parsing $_SERVER['QUERY_STRING']
with PHP. I would like to know whether it is syntactically correct to use hyphens in query string values such as in the following case, or whether hyphens must be escaped in the browser URL. What about underscores?
http://example.com/?q1=query-string-value-one&q2=query-string-value-two
According to this document hyphens should be OK in all standards-compliant browsers, but I wanted to double check.
Thanks.
The query component is a string of information to be interpreted by the resource. Within a query component, the characters ";", "/", "?", ":", "@", "&", "=", "+", ",", and "$" are reserved.
In JavaScript you can use the encodeURI() function. ASP has the Server. URLEncode() function.
Yes, it is valid.
As a matter of modern spec, yes, it is permissible to skip the slash, contrary to what the accepted answer here claims.
You are talking about query string parameters which must be encoded using urlencode
function:
This function is convenient when encoding a string to be used in a query part of a URL, as a convenient way to pass variables to the next page.
According to the documentation -
does not require encoding.
Yes
Hyphens can be used for query string parameter names
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With