Html url 变量中间的问号?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9357032/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 22:38:51  来源:igfitidea点击:

Question mark in the middle of a url variable?

htmlurlvariables

提问by townie

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 并且它有一个问号,我是否只需要转义问号?如果不是,我如何确保它像预期的那样通过?对不起,如果这是一个简单的问题,但我将需要这些信息,根据答案,我现在可能需要更改内容,如果我在不知情的情况下继续前进,这将是一团糟。

回答by David Schwartz

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. 但是你应该为整个事情使用一个合适的编码器,而不是手动编码一个字符。

回答by ElectroBit

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.

根据我尝试制作链接到 Google 的 JavaScript 搜索引擎的经验,只需将问号替换为%3F 即可。url 将%右侧的前两个字符读取为十六进制格式。

回答by DorkRawk

Here's a full listof 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 问题)。