www.webdeveloper.com
Results 1 to 5 of 5

Thread: Encode/decode URL

  1. #1
    Join Date
    Jan 2010
    Location
    Belgium
    Posts
    319

    Encode/decode URL

    I think this is a basic question, however, for some reason my small and simple script won't work ..

    Since my framework don't allow special characters, I have to encode an url. So for example domain.com/This_is_a_heart_♥ becomes domain.com/This_is_a_heart_%E2%99%A5

    But when I paste the second URL in the browser, the browser converts it back to domain.com/This_is_a_heart_♥ so the framework throws an error again.

    How can I fix this?

    Christophe

  2. #2
    Join Date
    Aug 2008
    Location
    Sweden
    Posts
    227
    Use encodeURI() or encodeURIComponent() to encode URLs.

  3. #3
    Join Date
    Jan 2010
    Location
    Belgium
    Posts
    319
    Yes, that's exactly what I'm doing. I use encodeURIComponent() to encode URL's but like said, the encoding itself works fine, but when I paste the following url in the webbrowser (i use chrome) the encoded url is decoded again, and my framework throws an error because 'illigal' characters are used.

    Try for yourself. Copy/paste the following url in the webbrowser and look at the URL. You'll see a heart at the end, instead of the encoding. domain.com/This_is_a_heart_%E2%99%A5

    Thanks for help!

    Christophe

  4. #4
    Join Date
    Aug 2008
    Location
    Sweden
    Posts
    227
    Ah, I see what you mean. Perhaps you could encode the URL twice then? So you'd get domain.com/This_is_a_heart_%25E2%2599%25A5 which Chrome doesn't seem to automatically decode.

  5. #5
    Join Date
    Jan 2010
    Location
    Belgium
    Posts
    319
    Hmm, that does work but doesn't seem the correct way to do it

    There must be a simple explanation, anybody?

    Thanks for the support refreezed!

    Christophe

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles