note 101248 modified in function.mysql-real-escape-string by danbrown
| From: | danbrown@php.net | Date: | Sun, 05 Dec 2010 16:44:58 +0000 |
| Subject: | note 101248 modified in function.mysql-real-escape-string by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-174627@lists.php.net to get a copy of this message | ||
Just a little function which mimics the original mysql_real_escape_string but which doesn't
need an active mysql connection. Could be implemented as a static function in a database class. Hope
it helps someone.
<?php
function mysql_escape_mimic($inp) {
if(is_array($inp))
return array_map(__METHOD__, $inp);
if(!empty($inp) && is_string($inp)) {
return str_replace(array('\\', "\0", "\n", "\r",
"'", '"', "\x1a"), array('\\\\', '\\0',
'\\n', '\\r', "\\'", '\\"', '\\Z'),
$inp);
}
return $inp;
}
?>
--was--
Just a little function which mimics the original mysql_real_escape_string but which doesn't
need an active mysql connection. Could be implemented as a static function in a database class. Hope
it helps someone.
function mysql_escape_mimic($inp) {
if(is_array($inp))
return array_map(__METHOD__, $inp);
if(!empty($inp) && is_string($inp)) {
return str_replace(array('\\', "\0", "\n", "\r",
"'", '"', "\x1a"), array('\\\\', '\\0',
'\\n', '\\r', "\\'", '\\"', '\\Z'),
$inp);
}
return $inp;
}
http://php.net/manual/en/function.mysql-real-escape-string.php