Skip to content

Instantly share code, notes, and snippets.

@a-eid
Created July 12, 2017 05:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save a-eid/5b9253fcb6dd8e0a7d7f307e897237cb to your computer and use it in GitHub Desktop.
Save a-eid/5b9253fcb6dd8e0a7d7f307e897237cb to your computer and use it in GitHub Desktop.
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