private static function process($value, $mode) { //原味输出 $input_type = array('get', 'post', 'request', 'server'); if (in_array($mode, $input_type, true)) { return $value; } //trim过滤、魔术引号转义 if (is_string($value)) { $value = get_magic_quotes_gpc() ? trim($value) : trim(addslashes($value)); } switch ($mode) { case 'title': //标题、关键词(去空、特殊字符、html标签) return trim(htmlspecialchars(strip_tags($value))); case 'int': //ID,自然数、POST的整型(0-N,ID、number) return abs((int) $value); case 'text': //介绍、详细内容(就留允许的html标签) $allow_tags = '<ul><ol><li><p><h1><h2><h3><h4><h5><h6><table><tr><th><td>'; $allow_tags .= '<a><img><span><b><i><em><cite><strong><br><hr>'; return trim(htmlspecialchars(strip_tags($value, $allow_tags))); case 'number': //数字 return regexp::match($value, 'number') ? $value : 0; case 'float': //小数、浮点数(货币、概率) return (double) $value; case 'account': //邮箱、用户名(注册账号时不区分大小写) return trim(secure::symbol(strip_tags(strtolower($value)))); case 'date': //日期 //日期 case 'time': //时间 //时间 case 'date_time': //日期时间 $option = array('date' => 'Y-m-d', 'time' => 'H:i:s', 'date_time' => 'Y-m-d H:i:s'); $format_time = date($option[$mode], strtotime($value)); return $format_time === $value ? $value : null; case 'many': //联合复选框(checkbox) return implode(',', $value); default: //正则匹配输出 return regexp::match($value, $mode) ? $value : null; } }