Difference between “+” and “%A0” - urlencoding?

有些话、适合烂在心里 提交于 2019-12-18 05:53:12

问题


I am url encoding a string of text to pass along to a function. However, it encodes the second space in a double-space as "%A0". This means that when I decode the string, the "%A0" is displayed as a question mark in a black box.

I really just need to be able to remove the extra space, but I'd like to understand what is causing this and how to handle it correctly.

For example:

Something  Something else

Encodes to:

Something+%A0Something+else

回答1:


%A0 indicates a NBSP (U+00A0). + indicates a normal space (U+0020). The NBSP displays as a replacement character (U+FFFD) because the encoding of the character does not match the encoding of the page, so its byte sequence is not valid for the page.




回答2:


A quick Googling shows that %A0 is the non-breaking space character or   in html. A + is the form-encoding for a standard space character.

Source




回答3:


The problem you're having is that the second "space" is not really a space, it's a character that that font doesn't have a glyph (I think that's the term) to represent (hence the black box with the question mark). %A0 is the escape code for that character. Your code is technically handling it correctly, I think the problem is with whatever is generating the string in the first place.




回答4:


If I refer to the chart on this page, %A0 is not a space. %20 is the space caracter's encoded value.



来源:https://stackoverflow.com/questions/6192788/difference-between-and-a0-urlencoding

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