Skip to content

Instantly share code, notes, and snippets.

@a-eid a-eid/urlencode.js
Created Jul 12, 2017

Embed
What would you like to do?
php like urlencode for javascript
// 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
You can’t perform that action at this time.