Javascript urlencode


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  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. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.