本文实例讲述了PHP简单字符串过滤方法。分享给大家供大家参考,具体如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
<!DOCTYPE html> <html lang= "zh-cn" > <head> <meta charset= "UTF-8" > <meta name= "viewport" content= "width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no" > <title>PHP字符串的过滤方法</title> </head> <body> <?php function strFilter( $str ){ //特殊字符的过滤方法 $str = str_replace ( '`' , '' , $str ); $str = str_replace ( '·' , '' , $str ); $str = str_replace ( '~' , '' , $str ); $str = str_replace ( '!' , '' , $str ); $str = str_replace ( '!' , '' , $str ); $str = str_replace ( '@' , '' , $str ); $str = str_replace ( '#' , '' , $str ); $str = str_replace ( '$' , '' , $str ); $str = str_replace ( '¥' , '' , $str ); $str = str_replace ( '%' , '' , $str ); $str = str_replace ( '^' , '' , $str ); $str = str_replace ( '……' , '' , $str ); $str = str_replace ( '&' , '' , $str ); $str = str_replace ( '*' , '' , $str ); $str = str_replace ( '(' , '' , $str ); $str = str_replace ( ')' , '' , $str ); $str = str_replace ( '(' , '' , $str ); $str = str_replace ( ')' , '' , $str ); $str = str_replace ( '-' , '' , $str ); $str = str_replace ( '_' , '' , $str ); $str = str_replace ( '——' , '' , $str ); $str = str_replace ( '+' , '' , $str ); $str = str_replace ( '=' , '' , $str ); $str = str_replace ( '|' , '' , $str ); $str = str_replace ( '\\' , '' , $str ); $str = str_replace ( '[' , '' , $str ); $str = str_replace ( ']' , '' , $str ); $str = str_replace ( '【' , '' , $str ); $str = str_replace ( '】' , '' , $str ); $str = str_replace ( '{' , '' , $str ); $str = str_replace ( '}' , '' , $str ); $str = str_replace ( ';' , '' , $str ); $str = str_replace ( ';' , '' , $str ); $str = str_replace ( ':' , '' , $str ); $str = str_replace ( ':' , '' , $str ); $str = str_replace ( '\'' , '' , $str ); $str = str_replace ( '"' , '' , $str ); $str = str_replace ( '“' , '' , $str ); $str = str_replace ( '”' , '' , $str ); $str = str_replace ( ',' , '' , $str ); $str = str_replace ( ',' , '' , $str ); $str = str_replace ( '<' , '' , $str ); $str = str_replace ( '>' , '' , $str ); $str = str_replace ( '《' , '' , $str ); $str = str_replace ( '》' , '' , $str ); $str = str_replace ( '.' , '' , $str ); $str = str_replace ( '。' , '' , $str ); $str = str_replace ( '/' , '' , $str ); $str = str_replace ( '、' , '' , $str ); $str = str_replace ( '?' , '' , $str ); $str = str_replace ( '?' , '' , $str ); //防sql防注入代码的过滤方法 $str = str_replace ( 'and' , '' , $str ); $str = str_replace ( 'execute' , '' , $str ); $str = str_replace ( 'update' , '' , $str ); $str = str_replace ( 'count' , '' , $str ); $str = str_replace ( 'chr' , '' , $str ); $str = str_replace ( 'mid' , '' , $str ); $str = str_replace ( 'master' , '' , $str ); $str = str_replace ( 'truncate' , '' , $str ); $str = str_replace ( 'char' , '' , $str ); $str = str_replace ( 'declare' , '' , $str ); $str = str_replace ( 'select' , '' , $str ); $str = str_replace ( 'create' , '' , $str ); $str = str_replace ( 'delete' , '' , $str ); $str = str_replace ( 'insert' , '' , $str ); $str = str_replace ( 'or' , '' , $str ); return trim( $str ); } $cont = ' ?”?;onestopweb.cn and update //\ as chaoyi 》、 ' ; echo '开始[' .strFilter( $cont ). ']结束' ; ?> </body> </html> |
效果图如下:
希望本文所述对大家PHP程序设计有所帮助。