Can hyphens be used in query string values?

大兔子大兔子 提交于 2019-12-05 17:54:09

问题


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.


回答1:


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.




回答2:


Yes

Hyphens can be used for query string parameter names



来源:https://stackoverflow.com/questions/32348875/can-hyphens-be-used-in-query-string-values

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!