Created
September 30, 2013 02:19
-
-
Save jeremejazz/6758651 to your computer and use it in GitHub Desktop.
Addslashes function from PHP.js
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 addslashes (str) { | |
// http://kevin.vanzonneveld.net | |
// + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) | |
// + improved by: Ates Goral (http://magnetiq.com) | |
// + improved by: marrtins | |
// + improved by: Nate | |
// + improved by: Onno Marsman | |
// + input by: Denny Wardhana | |
// + improved by: Brett Zamir (http://brett-zamir.me) | |
// + improved by: Oskar Larsson Högfeldt (http://oskar-lh.name/) | |
// * example 1: addslashes("kevin's birthday"); | |
// * returns 1: 'kevin\'s birthday' | |
return (str + '').replace(/[\\"']/g, '\\$&').replace(/\u0000/g, '\\0'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment