Skip to content

Instantly share code, notes, and snippets.

@caionitro
Created March 14, 2014 17:49
Show Gist options
  • Save caionitro/9552980 to your computer and use it in GitHub Desktop.
Save caionitro/9552980 to your computer and use it in GitHub Desktop.
Função mssql_real_scape_string()
function mssql_real_escape_string($data) {
$data = stripslashes(trim($data));
$data = strip_tags($data);
if ( !isset($data) or empty($data) ) return '';
if ( is_numeric($data) ) return $data;
$non_displayables = array(
'/%0[0-8bcef]/', // url encoded 00-08, 11, 12, 14, 15
'/%1[0-9a-f]/', // url encoded 16-31
'/[\x00-\x08]/', // 00-08
'/\x0b/', // 11
'/\x0c/', // 12
'/[\x0e-\x1f]/' // 14-31
);
foreach ( $non_displayables as $regex )
$data = preg_replace( $regex, '', $data );
$data = str_replace("'", "''", $data );
return $data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment