function mysql_escape_string($str) { $pattern = [ '/\x00/', '/\n/', '/\r/', '/\//', "/'/", '/"/', '/\x1a/', ]; $replacement = [ '\\x00', '\\n', '\\r', '\\', "\'", '\"', '\\x1a', ]; $res = preg_replace($pattern, $replacement, $str); return $res; }