Skip to content

Instantly share code, notes, and snippets.

@johnsardine
Created October 21, 2012 05:26
Show Gist options
  • Save johnsardine/3925992 to your computer and use it in GitHub Desktop.
Save johnsardine/3925992 to your computer and use it in GitHub Desktop.
Real Escape String
// Escapes a string or array just like mysql_real_escape_string but does not require a db connection like mysql_* one does
function real_escape_string($input) {
if(is_array($input))
return array_map(__METHOD__, $input);
if(!empty($input) && is_string($input)) {
return str_replace(array('\\', "\0", "\n", "\r", "'", '"', "\x1a"), array('\\\\', '\\0', '\\n', '\\r', "\\'", '\\"', '\\Z'), $input);
}
return $input;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment