Why should I use urlencode?

后端 未结 6 1162
别那么骄傲
别那么骄傲 2020-11-27 03:41

I am writing a web application and learning how to urlencode html links...

All the urlencode questions here (see tag below) are \"How to...?\" questions.

M

6条回答
  •  一整个雨季
    2020-11-27 04:03

    The main reason is it essentially escapes characters to be included in the URL of your webpage.

    Suppose a user inputs a user form field as "&joe" and we would like to redirect to a page which contains that name as part of the URL, using URL encoding, it would then be, for example:

    localhost/index.php?name=%26joe //note how the ampersand is escaped
    

    If you didnt use urlencoding, you would end up with:

    localhost/index.php?name=&joe
    

    and that ampersand would cause all sorts of unpredictability

提交回复
热议问题