Posted By

IanLewis on 05/29/08


Tagged

url encode


Versions (?)

Javascript urlencode


 / Published in: JavaScript
 

URL: http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_urlencode/

  1. function urlencode( str ) {
  2. // http://kevin.vanzonneveld.net
  3. // + original by: Philip Peterson
  4. // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  5. // * example 1: urlencode('Kevin van Zonneveld!');
  6. // * returns 1: 'Kevin+van+Zonneveld%21'
  7.  
  8. var ret = str;
  9.  
  10. ret = ret.toString();
  11. ret = encodeURIComponent(ret);
  12. ret = ret.replace(/%20/g, '+');
  13.  
  14. return ret;
  15. }

Report this snippet  

You need to login to post a comment.