======= PHP is worth recommending data verification class ===================================================================================================================================================================================
PHP CHECKER {// function defines var $ array_data = ""; // to verify the array data var $ var_key = ""; // Key Var $ VAR_VALUE = ""; // current The value of the data to be verified var $ is_empty = ""; // The value to verify can be empty VAR $ array_info = ""; // Tips Information Collect Var $ array_errors = array (); // Error message collection
// ---------------------> Constructor <------------ Function Checker ($ DATE) {$ this-> Array_data = $ date;}
// ---------------------> Data inspection function <------------ Function Check ($ array_datas) {foreach $ array_datas as $ value_key => $ value_v) {$ TEMP1 = EXPLODE ('|', $ value_v); if ($ TEMP1 [0] == "i_empty" and empty ($ this-> array_data [$ value_key])) {;} Else {foreach ($ TEMP1 AS $ TEMP_KEY => $ value_con) {
// $ data_temp = $ this-> array_data; // var_dump ($ data_temp ['birthday'); // echo "-". $ value_key. "-
"; $ this-> var_key = $ Value_Key; $ this-> var_value = $ this-> array_data [$ value_key];
$ TEMP2 = EXPLODE (':', $ value_con);
Switch ($ TEMP2)) {cas 0: $ this-> array_errors [$ this-> var_key] = "This value verification request does not exist"; Break; case 1: // If the user does not specify a verification action IF ( Empty ($ TEMP2 [0])) {$ this-> array_errors [$ this-> var_key] = "Verification request for this value"; Break;} else {$ this -> $ TEMP2 [0] (); // If the return value is not, it is not necessary to perform the next to verify Break;} Case 2: $ this -> $ TEMP2 [0] ($ TEMP2 [1]); Break; Case 3: $ this -> $ TEMP2 [0 ] ($ TEMP2 [1], $ TEMP2 [2]); Break;}}}}}} function i_empty ()} function i_empty () {$ this-> is_empty = 1; // This value is not used, just means that the value to verify can be Null value}
// Date data, email address, floating point data, integer, IP address, string, maximum, minimum, string length, domain name, URL / / ------------- -----> Date Verification -------------------- Function I_Date () {// Convention Format: 2000-02-01 or: 2000-5-4 IF (! EREGI ("^ [1-9] [0-9] - [0-9] - [0-9] $", $ this-> var_value) ) {$ This-> var_key] = "Date format error"; Return False;} $ TIME = STRTOTIME ($ this-> var_value); if ($ TIME === -1) {$ THIS -> array_errors [$ this-> var_key] = "Date Format Error"; Return False; $ TIME_E = EXPLODE ('-', $ this-> var_value); $ TIME_EX = EXPLODE ('-', DATE ('ym -D ', $ time)); for ($ I = 0; $ I
"; // Echo $ this-> var_value; Return True;} // --------------------> Floating point verification -------------------- Function i_float () {// if (! is_float ($ this-> var_value)) IF (! EREG ("^ [1-9] [0-9]? /. ([0-9]) $", $ this-> var_value)) $ this-> array_errors [$ this->
Var_key] = "This is not a decimal";} // --------------------> String verification ------------- ------- Function I_String () {i (Empty ($ this-> var_value)) // Allow empty return true; if (! is_string ($ this-> var_value) $ this-> array_errors [$ this-> var_key] = "This is not a string"; return true;} // -------------------> String length verification ----- --------------- Function LEN ($ MINV, $ Maxv = -1) {$ LEN = Strlen ($ this-> var_value); if ($ g == 0) {$ this-> array_errors [$ this-> var_key] = "No null value"; Return False;} IF ($ LEN <$ minv) {$ this-> array_errors [$ this-> var_key] = "input "Return false;} if ($ maxv! = -1) {IF ($ LEN> $ maxv) {$ this-> array_errors [$ this-> var_key] =" Enter the string too long "; Return False;}} Return True;} // --------------------> Integer verification ----------------- --- Function i_int () {ix (! EREG ("^ [0-9] * $", $ this-> var_value)) $ this-> array_errors [$ this-> var_key] = "This is not an integer" ;} // --------------------> IP address verification ------------------- Function I_IP () {if ("G (" ^ [0-9] {1, 3} /. [0-9] {1,3} /. [0-9] {1,3} /. [0-9 ] {1,3} $ ", $ THIS -> var_value)) {$ this-> array_errors [$ this-> var_key] = "Error IP address";} else {// Each is not greater than 255 $ array_temp = preg_split ("//./", worth worth?" -> var_value; foreach ($ array_temp as $ ip_value) {if ((int) $ ip_value> 255) $ this-> array_errors [$ this-> var_key] = "Error IP address";}}} Return True;} // --------------------> Maximum validation ------------------ Function I_max ($ Maxv) {if ($ this-> var_value> = $ maxv) {$ this-> array_errors [$ this-> var_key] = "data value is too big"; return true;} Return true;} // -------- ---------------->
Minimum verification ------------------- Function I_MIN ($ MINV) {IF ($ this-> var_value <= $ minv) {$ this-> array_errors [$ THIS-> var_key] = "Data value is too small"; return false;} Return True;} // ------------------> Domain name verification ---- ---------------- Function I_DOMAIN () {if (! EREGI ("^ @ ([0-9A-z / -_] /.) [0-9A- Z / -_】 $ ", $ this-> var_value)) $ this-> array_errors [$ this-> var_key] =" Error Domain Name "; Return EREGI (" @ (@ ([0-9A-z / - _] /.) [0-9A-z / -_] $ ", $ this-> var_value);} // ------------------- -> URL verification ------------------- function i_url () {if (! EREGI ('^ (http: // | https: //) {1} [A-Z0-9] (/. [A-Z0-9] ) $ ', $ this-> var_value)) $ this-> array_errors [$ this-> var_key] = "Error Web Address" Return True;} // --------------------> Custom Regular check ----------------- --- Function Check_own ($ user_pattern) {// custom verification. Error returning False, matching back 1, mismatch returns 0 $ TEMPVAR = preg_match ($ user_pattern, $ this-> var_value); if ($ TEMPVAR! = 1) $ this-> array_errors [$ this-> var_key] = "data Not legal ";} ################## THE END #################### ##############}
// <--------------------------------------- ----> / * // Note: If a value is allowed to be empty, you will have i_empty before verifying the array. //: The first first is the verification function, which is the parameter $ rule_list = array ('Temp' => 'Check_own: "^ @ ([0-9A-z / -_] /.) [0 -9A-z / -_] $ "',' Time '=>' i_time ',' fload '=>' i_float | i_min: 1 | i_max: 10.10 | len: 0: 20 ',' ipadr '=> 'i_ip', 'url' => 'i_URL', 'BirthDay' => 'i_date', 'Email' => 'i_Email | LEN: 1: 128', 'GENDER' => 'i_int | i_min: 1 | i_max : 20 ',' City '=>' i_String | LEN: 1: 32 '); $ rule_date = array (' Temp '=>' @ sina.com ',' Time '=> '23: 59: 00', 'fload' => '10.0 ',' ipadr '=>' 251.255.1.1 ',' url '=>' https://www.gg ',' birthday '=>' 2004-5-4 ',' GENDER '=>' 15 ',' email '=>' tonerzhang@sohu.com ',' city '=>' guangzhou ');
$ GG = New Checker ($ rule_date); $ GG-> Check ($ Rule_List);
Print_r ($ GG-> array_errors);
* /?>