Javascript addslashes : Strings : PHP functions in JavaScript JAVASCRIPT TUTORIALS


JAVASCRIPT TUTORIALS » PHP functions in JavaScript » Strings »

 

Javascript addslashes


Escapes single quote, double quotes and backslash characters in a string with backslashes
Example 1

Running
1.addslashes("kevin's birthday");

Could return
1.'kevin's birthday'
function addslashes( str ) {
    // Escapes single quote, double quotes and backslash characters in a string with backslashes  
    // 
    // version: 810.114
    // discuss at: http://phpjs.org/functions/addslashes
    // +   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
    // *     example 1: addslashes("kevin's birthday");
    // *     returns 1: 'kevin\'s birthday'
 
    return (str+'').replace(/([\\"'])/g, "\\$1").replace(/\0/g, "\\0");
}


HTML code for linking to this page:

Follow Navioo On Twitter

JAVASCRIPT TUTORIALS

 Navioo PHP functions in JavaScript
» Strings