& 符号不通过 url
在我的网站 www.gibberize.com 上,如果您在顶部文本区域中输入单词“and”,则该字符“&”将出现在第二个文本区域中。
问题是“tweet it”链接会将第二个文本区域的文本附加到 URL 并继续访问该链接,但因为它是一个 & 符号,所以会破坏文本。
有什么解决办法吗?
On my site www.gibberize.com if you type in the word "and" in the top textarea, the character "&" will appear in the second textarea.
The problem is that the "tweet it" link will then append the second textarea's text to a url and proceed to the link, but because it is an ampersand it will break the text.
Any solutions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用
encodeURIComponent
函数。您可以自己将其更改为%26
,但使用提供的函数更安全,因为这会处理传输中可能混乱的任何其他奇怪字符。Use the
encodeURIComponent
function. You could just change it to%26
yourself, but it's safer to use the function provided, as that will take care of any other odd characters that might get messed up in transmission.是的,在附加推文之前转义 & 符号,更改任何 & 符号。 %26。你可能想要
对整个文本
。注意:我建议的原始函数是 escape()。
Yes, escape the ampersand symbol before appending the tweet, change any & for %26. You may want to
the whole text.
Note: original function I suggested was escape().
使用 PHP 的
urlencode()
函数。Use PHP's
urlencode()
function.