Created
July 12, 2017 05:36
-
-
Save a-eid/5b9253fcb6dd8e0a7d7f307e897237cb to your computer and use it in GitHub Desktop.
php like urlencode for javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// rawurlencode is more or less like encodeURIComponent | |
function urlencode (str) { | |
// php like urlencode for javascript | |
str = (str + '') | |
return encodeURIComponent(str) | |
.replace(/!/g, '%21') | |
.replace(/'/g, '%27') | |
.replace(/\(/g, '%28') | |
.replace(/\)/g, '%29') | |
.replace(/\*/g, '%2A') | |
.replace(/%20/g, '+') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment