20,359
社区成员
发帖
与我相关
我的任务
分享
<?php
class Filter {
// 本方法用于返回一个已经过滤的,可以直接进行数据库操作的字符串,从 HTTP GET 方法
// the function can filter a string from the method GET of HTTP.
// public
static function http_get($var_name = null) {
// 如果没有相应的字符变量,则返回一个空字符串
if (is_null($var_name) or !isset($_GET[$var_name])) return '';
$hg = Filter :: filter_invalid($_GET[$var_name]);
$hg = trim($hg);
return $hg;
}
// 本方法用于返回一个已经过滤的,可以直接进行数据库操作的字符串,从 HTTP POST 方法
// the function can filter a string from the method POST of HTTP.
// public
static function http_post($var_name = null) {
// 如果没有相应的字符变量,则返回一个空字符串
if (is_null($var_name) or !isset($_POST[$var_name])) return '';
$hg = Filter :: filter_invalid($_POST[$var_name]);
$hg = trim($hg);
return $hg;
}
// 本方法用于过滤一串给定的字符.
// the function can filter a string from argument.
// public
static function filter_invalid($fi = null) {
// 如果没有相应的字符变量,则返回一个空字符串
if (is_null($fi)) return '';
// 转义特殊的 HTML 字符
$fi = htmlspecialchars($fi);
// 转义 \n 成 <br>
$fi = nl2br($fi);
// 如果没有魔术参数,那么就增加斜线
if (!get_magic_quotes_gpc()) {
$fi = addslashes($fi);
}
return $fi;
}
}
?>