Skip to content

Instantly share code, notes, and snippets.

@slouma2000
Created April 16, 2013 22:07
Show Gist options
  • Save slouma2000/5400057 to your computer and use it in GitHub Desktop.
Save slouma2000/5400057 to your computer and use it in GitHub Desktop.
jsAddSlashes
function jsAddSlashes($str) {
$pattern = array(
"/\\\\/" , "/\n/" , "/\r/" , "/\"/" ,
"/\'/" , "/&/" , "/</" , "/>/"
);
$replace = array(
"\\\\\\\\", "\\n" , "\\r" , "\\\"" ,
"\\'" , "\\x26" , "\\x3C" , "\\x3E"
);
return preg_replace($pattern, $replace, $str);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment