Last active
December 19, 2015 22:18
-
-
Save azhai/6026320 to your computer and use it in GitHub Desktop.
MySQL字符串数据过滤
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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