UNPKG

phpjs

Version:

php.js offers community built php functions in javascript

29 lines (28 loc) 922 B
function stripslashes(str) { // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) // + improved by: Ates Goral (http://magnetiq.com) // + fixed by: Mick@el // + improved by: marrtins // + bugfixed by: Onno Marsman // + improved by: rezna // + input by: Rick Waldron // + reimplemented by: Brett Zamir (http://brett-zamir.me) // + input by: Brant Messenger (http://www.brantmessenger.com/) // + bugfixed by: Brett Zamir (http://brett-zamir.me) // * example 1: stripslashes('Kevin\'s code'); // * returns 1: "Kevin's code" // * example 2: stripslashes('Kevin\\\'s code'); // * returns 2: "Kevin\'s code" return (str + '').replace(/\\(.?)/g, function(s, n1) { switch (n1) { case '\\': return '\\'; case '0': return '\u0000'; case '': return ''; default: return n1; } }); }