Class post_get{
Private $array; #提交表单检测字段和检测要求
# $type; Defaults to update or $type = "into";
Public Function _post_get ($array, $type = "") {
if (! $array) die ("error!!");
foreach ($array as $v)
{
$KK = $this->ck_split ($v);
$KKarray = Split ("_", $KK);
if (Preg_match ("/yes| No/is ", $KKarray [1]))
{
$escape _filter = ($KKarray [2])? ' Ck_ '. $KKarray [2]: ""; #需要转义和过滤
$data = ($escape _filter)? $this-> $escape _filter ($_post[$KKarray [0]]): $_post[$KKarray [0]]; #输出合法Data
if ($data)
{
if (Is_array ($data)) $data = Implode (",", $data);
$Into _data. = ", ' $data '";
$Into _field.= ", ' $KKarray [0] ';
$Updat _array[] = "' $KKarray [0] ' = ' $data '";
}
}
else $error. = ($KK)? "[". $KK. "],": ";
}
$_data= (! $type)? $Updat _array:array ("$Into _field", "$Into _data");
Return (! $error)? $_data: $this->ck_script ($error); # array is valid form validation result, string is error message hint
}
Public Function Ck_split ($STR) {
$strarray = Explode (",", $str);
foreach ($strarray as $i => $var)
if (0 = = $i)
$name = Trim ($var);
ElseIf (1=== $i)
{
if (eregi ("No", Trim ($var)) &&!$_post[$name]) break; #缺省忽略, otherwise ...
else $_type = (Trim ($var))? $name. ' _ '. Trim ($var): ""; #检测后动作
}
ElseIf (2=== $i)
{
$error = Trim ($var);
if (!$_post[$name])
{
$_error = $error;
Break
}
}
else # Detection Section
{
if (!trim ($var)) break;
if (Is_array ($_post[$name]))
{
foreach ($_post[$name] as $_var)
{
$_error= ($this->ck_open ($_var,trim ($var))) "": $error;
if ($_error) break;
}
}
Else
{
$_error= ($this->ck_open ($_post[$name],trim ($var))? ": $error;
if ($_error) break;
}
}
Return ($_error)? "" "$name." "," "$_error." "": $_type;
}
# window JS hint
Public Function Ck_script ($STR) {
$str = Trim ($str, ",");
$str = "
<script>
var str = new Array ($STR);
for (i=0 i < str.length; i++)
{
document.getElementById (' J ' +str[0]+ ']. innerhtml= str[1];
}
</script>
";
return $str;
}
# type Judgment
Public Function ck_detected ($STR) {
Return (eregi ("^[a-za-z]*$", $str))? ' Ck_ '. $str: ' Ck_length ';
}
#functionCall
Public Function Ck_open ($string, $str) {
$functi = $this->ck_detected ($STR);
Return ($this-> $functi ($string, $str))? True:false;
}
#-------------------------------------The following as the detection function
# length
Public Function Ck_length ($string, $str) {
$len = Split ('-', trim ($STR));
Return (strlen ($string) > ($len [0]-1) && strlen ($string) < ($len [1]+1)]? True:false;
}
# Price
Public Function Ck_money ($STR) {
Return Preg_match ("/^ (-|+)" d+ (. d+) $/", $str);
}
# Mail
Public Function Ck_email ($STR) {
Return Preg_match ("/^w+ [-+.] w+) *@w+ ([-.] w+) *.w+ ([-.] w+) *$/", $str);
}
# Web site
Public Function Ck_url ($STR) {
Return Preg_match ("/^http://[a-za-z0-9]+.[ a-za-z0-9]+[/=?%-&_~ ' @[] ': +!] * ([^<> "]) *$/", $str);
}
# Digital Type
Public Function Ck_num ($STR) {
Return Is_numeric ($STR);
}
# Chinese
Public Function Ck_cn ($STR) {
Return Preg_match ("/^[x7f-xff]+$/", $str);
}
# Letters
Public Function Ck_en ($STR) {
Return Preg_match ("/^[a-za-z]+$/", $str);
}
# Digital Alphabet Mix
Public Function Ck_numen ($STR) {
Return Preg_match ("/^ ([a-za-z0-9_-]) +$/", $str);
}
# phone Number
Public Function Ck_tel ($STR) {
Return Ereg ("^[+]?[ 0-9]+ ([xx-][0-9]+) *$ ", $str);
}
# sensitive words
Public Function Ck_key ($STR) {
Global $badkey;
Return (!preg_match ("/$badkey/I", $str));
}
#-----------------------------------------------------Output
# character Substitution
Public Function Ck_filter ($STR) {
$str = (Is_array ($str))? Implode (",", $str): $str;
$str =htmlspecialchars ($STR); Converts a special character into HTML format.
$str =nl2br ($STR); Replace the carriage return with the <br>
$str =str_replace (Array ("", ';? '), Array ("", ' < '), $STR); Replace a space with
return $str;
}
# MD5 Encryption
Public Function Ck_md ($STR) {
Return MD5 ($STR);
}
# escape
Public Function Ck_escape ($STR) {
Return (Is_array ($STR))? Implode (",", $str): $str;
}
# conditional Cancellation (number)
Public Function Ck_cancel ($STR) {
Return (!is_numeric ($STR))? $STR: "";
}
# unconditional Cancellation (number)
Public Function Ck_delete () {
return null;
}
}