PHP universal detection function set .? [File name]: c_check.inc [function]: universal detection function set [author]: Tianyao [last modification date]: 20010511 [cxx] [variable definition rule]: 'c _ struct type // [File name]: c_check.inc 
// [For use]: universal detection function set 
// [Operator]: Tianyao 
// [Last modification date]: 2001/05/11 [cxx] 
// [Variable definition rules]: 'c _ '= numeric type,' I _ '= integer type, 'n' _' = numeric type, 'L _ '= Boolean type, 'A _ '= array type 
 
//-------------------------------------------------- 
// ※Checkmoney ($ C_Money) checks whether the data is in the 99999.99 format. 
// ※Checkemailaddr ($ C_mailaddr) determines whether the email address is valid. 
// ※Checkwebaddr ($ C_weburl) 
// ※Checkempty ($ C_char) determines whether the string is null. 
// ※Checklengthbetween ($ C_char, $ I _len1, $ I _len2 = 100) 
// ※Checkuser ($ C_user) determines whether the user name is valid. 
// ※Checkpassword ($ C_passwd) determines whether the password is valid. 
// ※Checktelephone ($ C_telephone) 
// ※Checkvaluebetween ($ N_var, $ N_val1, $ N_val2) determines whether the value is valid within a certain range. 
// ※Checkpost ($ C_post) determines whether the postal code is valid (fixed length) 
// ※Checkextendname ($ C_filename, $ A_extend) indicates the extension of the uploaded file. 
// ※Checkimagesize ($ ImageFileName, $ LimitSize) indicates the size of the uploaded image. 
// ※Alertexit ($ C_alert, $ I _goback = 0) indicates an invalid operation and exits. 
// ※Alert ($ C_alert, $ I _goback = 0) indicates an invalid operation warning. 
// ※Replacespacialchar ($ C_char) special character replacement function 
// ※Exchangemoney ($ N_money) fund conversion function 
// ※Windowlocation ($ C_url, $ C_get = "", $ C_getOther = "") function of window. location in PHP 
//-------------------------------------------------- 
 
//-------------------------------------------------- 
// Function name: CheckMoney ($ C_Money) 
// For usage: Check whether the data is in the 99999.99 format 
// Parameter: $ C_Money (number to be detected) 
// Return value: Boolean 
// Standby Note: None 
//-------------------------------------------------- 
Function CheckMoney ($ C_Money) 
{ 
If (! Ereg ("^ [0-9] [.] [0-9] $", $ C_Money) return false; 
Return true; 
} 
//-------------------------------------------------- 
 
//-------------------------------------------------- 
// Function name: CheckEmailAddr ($ C_mailaddr) 
// Usage: determines whether the email address is a valid email address. 
// Parameter: $ C_mailaddr (email address to be detected) 
// Return value: Boolean 
// Standby Note: None 
//-------------------------------------------------- 
Function CheckEmailAddr ($ C_mailaddr) 
{ 
If (! Eregi ("^ [_ a-z0-9-] + (. [_ a-z0-9-] +) * @ [a-z0-9-] + (. [a-z0-9-] +) * $ ", 
$ C_mailaddr )) 
//(! Ereg ("^ [_ a-zA-Z0-9-] + (. [_ a-zA-Z0-9-] +) * @ [_ a-zA-Z0-9-] + (. [_ a-zA-Z0-9-] +) * $ ", 
$ C_mailaddr )) 
{ 
Return false; 
} 
Return true; 
} 
//-------------------------------------------------- 
 
//-------------------------------------------------- 
// Function name: CheckWebAddr ($ C_weburl) 
// Usage: Determine whether the website is valid 
// Parameter: $ C_weburl (URL to be detected) 
// Return value: Boolean 
// Standby Note: None 
//-------------------------------------------------- 
Function CheckWebAddr ($ C_weburl) 
{ 
If (! Ereg ("^ http: // [_ a-zA-Z0-9-] + (. [_ a-zA-Z0-9-] +) * $", $ C_weburl )) 
{ 
Return false; 
} 
Return true; 
} 
//-------------------------------------------------- 
 
//-------------------------------------------------- 
// Function name: CheckEmpty ($ C_char) 
// For usage: determines whether the string is null. 
// Parameter: $ C_char (string to be detected) 
// Return value: Boolean 
// Standby Note: None 
//-------------------------------------------------- 
Function CheckEmptyString ($ C_char) 
{ 
If (! Is_string ($ C_char) return false; // whether it is a string type 
If (empty ($ C_char) return false; // whether it is set 
If ($ C_char = '') return false; // whether it is null 
Return true; 
} 
//-------------------------------------------------- 
 
//-------------------------------------------------- 
// Function name: CheckLengthBetween ($ C_char, $ I _len1, $ I _len2 = 100) 
// For usage: determines whether the string is within the specified length 
// Parameter: $ C_char (string to be detected) 
// $ I _len1 (lower limit of the target string length) 
// $ I _len2 (maximum length of the target string) 
// Return value: Boolean 
// Standby Note: None 
//-------------------------------------------------- 
Function CheckLengthBetween ($ C_cahr, $ I _len1, $ I _len2 = 100) 
{ 
$ C_cahr = trim ($ C_cahr ); 
If (strlen ($ C_cahr) <$ I _len1) return false; 
If (strlen ($ C_cahr)> $ I _len2) return false; 
Return true; 
} 
//-------------------------------------------------- 
 
//-------------------------------------------------- 
// Function name: CheckUser ($ C_user) 
// Usage: determines whether the user name is valid 
// Parameter: $ C_user (user name to be detected) 
// Return value: Boolean 
// Standby Note: None 
//-------------------------------------------------- 
Function CheckUser ($ C_user) 
{ 
If (! CheckLengthBetween ($ C_user, 4, 20) return false; // width check 
If (! Ereg ("^ [_ a-zA-Z0-9] * $", $ C_user) return false; // special character check 
Return true; 
} 
//-------------------------------------------------- 
 
//-------------------------------------------------- 
// Function name: CheckPassword ($ C_passwd) 
// Usage: determines whether the password is valid. 
// Parameter: $ C_passwd (password to be detected) 
// Return value: Boolean 
// Standby Note: None 
//-------------------------------------------------- 
Function CheckPassword ($ C_passwd) 
{ 
If (! CheckLengthBetween ($ C_passwd, 4, 20) return false; // width detection 
If (! Ereg ("^ [_ a-zA-Z0-9] * $", $ C_passwd) return false; // special character detection 
Return true; 
} 
//-------------------------------------------------- 
 
//-------------------------------------------------- 
// Function name: CheckTelephone ($ C_telephone) 
// Usage: determines whether the phone number is a legal phone number. 
// Parameter: $ C_telephone (phone number to be detected) 
// Return value: Boolean 
// Standby Note: None 
//-------------------------------------------------- 
Function CheckTelephone ($ C_telephone) 
{ 
If (! Ereg ("^ [+]? [0-9] + ([xX-] [0-9] +) * $ ", $ C_telephone) return false; 
Return true; 
} 
//-------------------------------------------------- 
 
//-------------------------------------------------- 
// Function name: CheckValueBetween ($ N_var, $ N_val1, $ N_val2) 
// Usage: determines whether the value is valid within a certain range. 
// Parameter: $ N_var value to be detected 
// $ N_var1 upper limit of the value to be detected 
// $ N_var2 lower limit of the value to be detected 
// Return value: Boolean 
// Standby Note: None 
//-------------------------------------------------- 
Function CheckValueBetween ($ N_var, $ N_val1, $ N_val2) 
{ 
If ($ N_var <$ N_var1 │ $ N_var> $ N_var2) 
{ 
Return false; 
} 
Return true; 
 
} 
//-------------------------------------------------- 
 
//-------------------------------------------------- 
// Function name: CheckPost ($ C_post) 
// Usage: Determine whether the zip code is valid (fixed length) 
// Parameter: $ C_post (zip code to be checked) 
// Return value: Boolean 
// Standby Note: None 
//-------------------------------------------------- 
Function CheckPost ($ C_post) 
{ 
$ C_post = trim ($ C_post ); 
If (strlen ($ C_post) = 6) 
{ 
If (! Ereg ("^ [+]? [_ 0-9] * $ ", $ C_post )) 
{ 
Return true ;; 
} Else 
{ 
Return false; 
} 
} Else 
{ 
Return false ;; 
} 
} 
//-------------------------------------------------- 
 
//-------------------------------------------------- 
// Function name: CheckExtendName ($ C_filename, $ A_extend) 
// Usage: determine the extension of the uploaded file 
// Parameter: $ C_filename: name of the uploaded file 
// $ A_extend required extension 
// Return value: Boolean 
// Standby Note: None 
//-------------------------------------------------- 
Function CheckExtendName ($ C_filename, $ A_extend) 
{ 
If (strlen (trim ($ C_filename) <5) 
{ 
Return 0; // if 0 is returned, the image is not uploaded. 
} 
$ Lastdot = strrpos ($ C_filename, "."); // retrieves the last position that appears. 
$ Extended = substr ($ C_filename, $ lastdot + 1); // Retrieve the extension 
 
For ($ I = 0; $ I  { 
If (trim (strtolower ($ extended) = trim (strtolower ($ A_extend [$ I]) // Large conversion 
Lowercase and detection 
{ 
$ Flag = 1; // add a success flag 
$ I = count ($ A_extend); // if it is detected, the detection is stopped. 
} 
} 
 
If ($ flag <> 1) 
{ 
For ($ j = 0; $ j  { 
$ Alarm. = $ A_extend [$ j]. ""; 
} 
AlertExit ('upload only '. $ alarm.' file! And you uploaded '. $ extended.' type File '); 
Return-1; // return-1 indicates the type of the uploaded image does not match 
} 
 
Return 1; // return 1 indicates that the image type meets the requirements. 
} 
//-------------------------------------------------- 
 
//-------------------------------------------------- 
// Function name: CheckImageSize ($ ImageFileName, $ LimitSize) 
// Usage: check the size of the uploaded image 
// Parameter: name of the image uploaded by $ ImageFileName 
// The size required by $ LimitSize 
// Return value: Boolean 
// Standby Note: None 
//-------------------------------------------------- 
Function CheckImageSize ($ ImageFileName, $ LimitSize) 
{ 
$ Size = GetImageSize ($ ImageFileName ); 
If ($ size [0]> $ LimitSize [0] | $ size [1]> $ LimitSize [1]) 
{ 
AlertExit ('large Image size '); 
Return false; 
} 
Return true; 
} 
//-------------------------------------------------- 
 
//-------------------------------------------------- 
// Function name: Alert ($ C_alert, $ I _goback = 0) 
// Usage: illegal operation warning 
// Parameter: $ C_alert (error message) 
// $ I _goback (return to that page) 
// Return value: string 
// Standby Note: None 
//-------------------------------------------------- 
Function Alert ($ C_alert, $ I _goback = 0) 
{ 
If ($ I _goback <> 0) 
{ 
Echo "script" alert ('$ C_alert'); history. go ($ I _goback); script "; 
} 
Else 
{ 
Echo "script" alert ('$ C_alert'); script "; 
} 
} 
//-------------------------------------------------- 
 
//-------------------------------------------------- 
// Function name: AlertExit ($ C_alert, $ I _goback = 0) 
// Usage: illegal operation warning 
// Parameter: $ C_alert (error message) 
// $ I _goback (return to that page) 
// Return value: string 
// Standby Note: None 
//-------------------------------------------------- 
Function AlertExit ($ C_alert, $ I _goback = 0) 
{ 
If ($ I _goback <> 0) 
{ 
Echo "script" alert ('$ C_alert'); history. go ($ I _goback); script "; 
Exit; 
} 
Else 
{ 
Echo "script" alert ('$ C_alert'); script "; 
Exit; 
} 
} 
//-------------------------------------------------- 
 
//-------------------------------------------------- 
// Function name: ReplaceSpacialChar ($ C_char) 
// For usage: special character replacement function 
// Parameter: $ C_char (string to be replaced) 
// Return value: string 
// Standby Note: None 
//-------------------------------------------------- 
Function ReplaceSpecialChar ($ C_char) 
{ 
$ C_char = HTMLSpecialChars ($ C_char); // Convert Special characters into HTML format. 
$ C_char = nl2br ($ C_char); // replace the carriage return 
 
$ C_char = str_replace ("", "", $ C_char); // replace spaces 
$ C_char = str_replace (" Return $ C_char; 
} 
//-------------------------------------------------- 
 
//-------------------------------------------------- 
// Function name: ExchangeMoney ($ N_money) 
// For use: capital conversion function 
// Parameter: $ N_money (number of the amount to be converted) 
// Return value: string 
// Standby note: This function example: $ char = ExchangeMoney (5645132.3155) ==>$ char = '¥ 5,645,132.31' 
//-------------------------------------------------- 
Function ExchangeMoney ($ N_money) 
{ 
$ A_tmp = explode (".", $ N_money); // divide the number into two parts by the decimal point, and store the array $ A_tmp 
$ I _len = strlen ($ A_tmp [0]); // measure the width of the digits before the decimal point. 
 
If ($ I _len % 3 = 0) 
{ 
$ I _step = $ I _len/3; // for example, the width of the previous digit mod 3 = 0, which can be divided into $ I _step 
Part 
} Else 
{ 
$ Step = ($ len-$ len % 3)/3 + 1; // for example, the width of the previous digit mod 3! = 0, which can be divided into $ I _step 
Part + 1 
} 
 
$ C_cur = ""; 
// Convert the amount before the decimal point 
While ($ I _len <> 0) 
{ 
$ I _step --; 
 
If ($ I _step = 0) 
{ 
$ C_cur. = substr ($ A_tmp [0], 0, $ I _len-($ I _step) * 3 ); 
} Else 
{ 
$ C_cur. = substr ($ A_tmp [0], 0, $ I _len-($ I _step) * 3 ).","; 
} 
 
$ A_tmp [0] = substr ($ A_tmp [0], $ I _len-($ I _step) * 3 ); 
$ I _len = strlen ($ A_tmp [0]); 
} 
 
// Convert the amount after the decimal point 
If ($ A_tmp [1] = "") 
{ 
$ C_cur. = ". 00 "; 
} Else 
{ 
$ I _len = strlen ($ A_tmp [1]); 
If ($ I _len <2) 
{ 
$ C_cur. = ".". $ A_tmp [1]. "0 "; 
} Else 
{ 
$ C_cur. = ".". substr ($ A_tmp [1], 0, 2 ); 
} 
} 
 
// Add and transfer the RMB symbol 
$ C_cur = "¥". $ C_cur; 
Return $ C_cur; 
} 
//-------------------------------------------------- 
 
//------------------------------------------------- 
// Function name: WindowLocation ($ C_url, $ C_get = "", $ C_getOther = "") 
// Usage: window. location function in PHP 
// Parameter: $ C_url indicates the URL of the redirection window. 
// $ C_get method parameters 
// $ C_getOther other parameters of the GET method 
// Return value: string 
// Standby Note: None 
//------------------------------------------------ 
Function WindowLocation ($ C_url, $ C_get = "", $ C_getOther = "") 
{ 
If ($ C_get = "" & $ C_getOther = "") 
If ($ C_get = "" & $ C_getOther <> "") {$ C_target = "" window. location = '$ C_url? 
$ C_getOther = '+ this. value "";} 
If ($ C_get <> "" & $ C_getOther = ") {$ C_target =" "window. location = '$ C_url? 
$ C_get '"";} 
If ($ C_get <> "" & $ C_getOther <> "") {$ C_target = "" window. location = '$ C_url? 
$ C_get & $ C_getOther = '+ this. value "";} 
Return $ C_target; 
} 
//------------------------------------------------ 
?> 
 
 
 
 
Http://www.bkjia.com/PHPjc/317041.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/317041.htmlTechArticle? // [File name]: c_check.inc/[function]: universal detection function set // [author]: Tianyao // [last modification date ]: 2001/05/11 [cxx] // [variable definition rule]: 'c _ '= struct type...