Last active
April 20, 2018 04:37
-
-
Save welefen/4ce5a1edf89bbcf9cf54 to your computer and use it in GitHub Desktop.
js实现php里的rawurlencode和urlencode
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
function rawurlencode(str) { | |
str = (str+'').toString(); | |
return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').replace(/\)/g, '%29').replace(/\*/g, '%2A'); | |
} | |
function urlencode(str) { | |
return escape(str).replace(/\+/g,'%2B').replace(/%20/g, '+').replace(/\*/g, '%2A').replace(/\//g, '%2F').replace(/@/g, '%40'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment