Alternative to mysql_real_escape_string without connecting to DB

Well, according to the mysql_real_escape_string function reference page: 'mysql_real_escape_string() calls MySQL's library function mysql_real_escape_string, which escapes the following characters: x00, n, r, , ', ' and x1a.'

function mres($value)
{
    $search = array('\',  'x00', 'n',  'r',  ''',  ''', 'x1a');
    $replace = array('\\','\0','\n', '\r', ''', ''', '\Z');    return str_replace($search, $replace, $value);
}