SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: urlencode()

  1. #1
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)

    urlencode()

    Does Javascript have an equivilant or does anyone know of any JS code libraries that have a function that is the same as PHP's urlencode()?

    Ta

  2. #2
    SitePoint Addict xDev's Avatar
    Join Date
    Jul 2003
    Location
    Moncton, New Brunswick, Canada
    Posts
    247
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes there is an equivalent. escape() and unescape()

    Code:
    <script type="text/javascript">
    var urlEncode = escape("http://www.xdevdesign.com/Page with space.htm"); 
    document.write(urlEncode);
    // Prints: http%3A//www.xdevdesign.com/Page%20with%20space.htm 
    </script>
    JavaScript escape and unescape functions operate slightly differently from PHP: they encode space as "%20", and treat "+" as a safe character

    Unicode characters will be converted to the Unicode escape-sequences %uXXXX in javascript version 1.3 and up.

    There's a new function (encodeURI) in javascript 1.5 that should give better results:
    http://devedge.netscape.com/library/...v.html#1118346

    -xDev


Bookmarks

Posting Permissions

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