/ Published in: JavaScript
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function urlencode( str ) { // http://kevin.vanzonneveld.net // + original by: Philip Peterson // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) // * example 1: urlencode('Kevin van Zonneveld!'); // * returns 1: 'Kevin+van+Zonneveld%21' var ret = str; ret = ret.toString(); ret = encodeURIComponent(ret); ret = ret.replace(/%20/g, '+'); return ret; }
URL: http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_urlencode/