Skip to content

Instantly share code, notes, and snippets.

@azhai
Last active December 19, 2015 22:18
Show Gist options
  • Save azhai/6026320 to your computer and use it in GitHub Desktop.
Save azhai/6026320 to your computer and use it in GitHub Desktop.
MySQL字符串数据过滤
<?php
/* 过滤$_REQUEST字符串中的危险字符,用于mysql查询 */
function str2db($input, $strip_tags=true) {
if(is_array($input)) {
foreach($input as $key => $value) {
$input[$key] = str2db($value);
}
} else {
if(get_magic_quotes_gpc()) {
if(ini_get('magic_quotes_sybase')){
$input = str_replace("''", "'", $input);
}
else {
$input = stripslashes($input);
}
}
if($strip_tags) {
$input = strip_tags($input);
}
$input = mysql_real_escape_string($input);
$input = trim($input);
}
return $input;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment