url变量中间的问号?

时间:2022-01-14 22:28:17

If I have a variable to pass through a url and it has a question mark in it, do I just need to escape the question mark? If not how can I make sure it passes through like it's supposed to? Sorry if this is a simple question but I will need this info down the line and depending on the answer I might need to change stuff now that will be a mess if I go forward without knowing.

如果我有一个变量要通过一个url,它有一个问号,我需要转义问号吗?如果不是,我怎么能确保它像它应该的那样通过呢?抱歉,如果这是一个简单的问题,但我需要这个信息,根据我可能需要改变的答案,如果我继续下去而不知道,那将是一团糟。

3 个解决方案

#1


50  

A question mark URL encodes as %3F. But you should use a proper encoder for the whole thing rather than manually encoding a character.

问号URL编码为%3F。但是,您应该使用一个合适的编码器,而不是手工编码一个字符。

#2


7  

Here's a full list of URL encoding characters. If you're using PHP for a server side language, you can use something like...

这是URL编码字符的完整列表。如果您使用PHP作为服务器端语言,您可以使用以下内容:

$nice_url = urlencode("http://your.old.url");

Other languages will have similar functions build in (or you can find one online). This will take care of your question mark (and other url issues).

其他语言也会内置类似的功能(或者你可以在网上找到)。这将处理您的问号(以及其他url问题)。

#3


5  

According to my experience of trying to make a JavaScript search engine that links to Google, just replace the question marks with %3F. A url reads the first two characters on the right of a % as hexadecimal format.

根据我的经验,尝试创建一个链接到谷歌的JavaScript搜索引擎,只需用%3F替换问号。url将以%为十六进制格式的右边的前两个字符读取。

#1


50  

A question mark URL encodes as %3F. But you should use a proper encoder for the whole thing rather than manually encoding a character.

问号URL编码为%3F。但是,您应该使用一个合适的编码器,而不是手工编码一个字符。

#2


7  

Here's a full list of URL encoding characters. If you're using PHP for a server side language, you can use something like...

这是URL编码字符的完整列表。如果您使用PHP作为服务器端语言,您可以使用以下内容:

$nice_url = urlencode("http://your.old.url");

Other languages will have similar functions build in (or you can find one online). This will take care of your question mark (and other url issues).

其他语言也会内置类似的功能(或者你可以在网上找到)。这将处理您的问号(以及其他url问题)。

#3


5  

According to my experience of trying to make a JavaScript search engine that links to Google, just replace the question marks with %3F. A url reads the first two characters on the right of a % as hexadecimal format.

根据我的经验,尝试创建一个链接到谷歌的JavaScript搜索引擎,只需用%3F替换问号。url将以%为十六进制格式的右边的前两个字符读取。