可以在查询字符串值中使用连字符吗?

Can hyphens be used in query string values?

我的问题与 this one 有关。除了我的问题更具体,因为它是关于是否可以在查询字符串参数值中使用连字符。

我正在用 PHP 解析 $_SERVER['QUERY_STRING']。我想知道在查询字符串值中使用连字符在语法上是否正确,例如在以下情况中,或者是否必须在浏览器中转义连字符 URL。下划线呢?

http://example.com/?q1=query-string-value-one&q2=query-string-value-two

根据 this document 连字符在所有符合标准的浏览器中都应该没问题,但我想仔细检查一下。

谢谢。

您正在谈论必须使用 urlencode 函数编码的查询字符串参数:

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.

根据文档-不需要编码。

连字符可用于查询字符串参数名称