Thunder High-Speed Channel Unlimited use PHP Universal detection function Collection

Source: Internet
Author: User
Tags ereg valid email address
"File name": C_check.inc
"Function": Universal set of test functions
"Author": Tian Ash
"Last Modified Date": 2001/05/11[cxx]
"Variable definition rule": ' c_ ' = character type, ' i_ ' = integer, ' n_ ' = numeric, ' L_ ' = boolean, ' a_ ' = array type
//--------------------------------------------------
※checkmoney ($C _money) Check if the data is in 99999.99 format
※CHECKEMAILADDR ($C _mailaddr) to determine if a valid e-mail address
※CHECKWEBADDR ($C _weburl) to determine if it is a valid URL
※checkempty ($C _char) to determine if a string is empty
※checklengthbetween ($C _char, $I _len1, $I _len2=100) determines whether a string is within a specified length
※checkuser ($C _user) to determine if it is a valid user name
※checkpassword ($C _passwd) determine if the password is a valid user
※checktelephone ($C _telephone) to determine if it is a legitimate phone number
※checkvaluebetween ($N _var, $N _val1, $N _val2) to determine whether a range of legal values
※checkpost ($C _post) determine if it is a valid ZIP code (fixed length)
※checkextendname ($C _filename, $A _extend) determine the extension of the uploaded file
※checkimagesize ($ImageFileName, $LimitSize) Verify the size of the uploaded image
※alertexit ($C _alert, $I _goback=0) Illegal operation warning and exit
※alert ($C _alert, $I _goback=0) Illegal operation warning
※replacespacialchar ($C _char) special character substitution function
※exchangemoney ($N _money) Money conversion function
※windowlocation ($C _url, $C _get= "", $C _getother= "") window.location function in PHP
//--------------------------------------------------
//--------------------------------------------------
Function name: Checkmoney ($C _money)
Role: Check whether the data is in 99999.99 format
Parameters: $C _money (number to be detected)
Return Value: Boolean value
Remark: None
//--------------------------------------------------
function Checkmoney ($C _money)
{
if (!ereg ("^[0-9][.") [0-9]$ ", $C _money)) return false;
return true;
}
//--------------------------------------------------
//--------------------------------------------------
Function name: checkemailaddr ($C _mailaddr)
Role: Determine whether a valid email address
Parameters: $C _mailaddr (e-mail address to be detected)
Return Value: Boolean value
Remark: 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)
Function: Determine if it is a valid URL
Parameters: $C _weburl (URL to be detected)
Return Value: Boolean value
Remark: 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)
Function: Determines whether the string is empty
Parameters: $C _char (string to be detected)
Return Value: Boolean value
Remark: 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 has been set
if ($C _char== ") return false; is empty
return true;
}
//--------------------------------------------------
//--------------------------------------------------
Function name: Checklengthbetween ($C _char, $I _len1, $I _len2=100)
Function: Determines whether the string is within the specified length
Parameters: $C _char (string to be detected)
$I _len1 (the lower bound of the target string length)
$I _len2 (upper limit of target string length)
Return Value: Boolean value
Remark: 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)
Role: Determine whether a valid user name
Parameters: $C _user (user name to be detected)
Return Value: Boolean value
Remark: None
//--------------------------------------------------
function CheckUser ($C _user)
{
if (! Checklengthbetween ($C _user, 4,)) return false; Width test
if (!ereg ("^[_a-za-z0-9]*$", $C _user)) return false; Special character test
return true;
}
//--------------------------------------------------
//--------------------------------------------------
Function name: Checkpassword ($C _passwd)
Role: Determine if the password is a valid user
Parameters: $C _passwd (password to be detected)
Return Value: Boolean value
Remark: None
//--------------------------------------------------
function Checkpassword ($C _passwd)
{
if (! Checklengthbetween ($C _passwd, 4,)) return false; Width detection
if (!ereg ("^[_a-za-z0-9]*$", $C _passwd)) return false; Special character detection
return true;
}
//--------------------------------------------------
//--------------------------------------------------
Function name: Checktelephone ($C _telephone)
Role: Determine whether a legal phone number
Parameters: $C _telephone (phone number to be detected)
Return Value: Boolean value
Remark: 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)
Function: Determine whether a certain range of legal values
Parameters: $N _var value to be detected
$N _VAR1 The maximum value to be detected
$N _var2 The lower limit of the value to be detected
Return Value: Boolean value
Remark: 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)
Function: Determine whether it is a valid postcode (fixed length)
Parameter: $C _post (zip code to check)
Return Value: Boolean value
Remark: 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)
Role: Upload file extension judgment
Parameters: $C file name uploaded by _filename
$A _extend Required Extensions
Return Value: Boolean value
Remark: None
//--------------------------------------------------
function Checkextendname ($C _filename, $A _extend)
{
if (strlen (Trim ($C _filename)) < 5)
{
return 0; Returns 0 to indicate that no pictures were uploaded
}
$lastdot = Strrpos ($C _filename, "."); Take out. The last place to appear
$extended = substr ($C _filename, $lastdot + 1); Remove extension
for ($i =0; $i {
if (Trim (Strtolower ($extended)) = = Trim (Strtolower ($A _extend[$i]))//Convert Large
Lowercase and detect
{
$flag = 1; Add Success Flag
$i =count ($A _extend); Stop detection detected
}
}
if ($flag <>1)
{
for ($j =0; $j {
$alarm. = $A _extend[$j]. " ";
}
Alertexit (' Upload only '. $alarm. ' File! And you're uploading '. $extended. ' Files of type ');
return-1; Returns-1 indicates that the type of the uploaded picture does not match
}
return 1; Returns 1 indicates that the type of picture meets the requirements
}
//--------------------------------------------------
//--------------------------------------------------
Function name: Checkimagesize ($ImageFileName, $LimitSize)
Role: Verify the size of the uploaded image
Parameters: $ImageFileName The name of the uploaded picture
$LimitSize the required dimensions
Return Value: Boolean value
Remark: None
//--------------------------------------------------
function Checkimagesize ($ImageFileName, $LimitSize)
{
$size =getimagesize ($ImageFileName);
if ($size [0]> $LimitSize [0] | | $size [1]> $LimitSize [1])
{
Alertexit (' picture size is too large ');
return false;
}
return true;
}
//--------------------------------------------------
//--------------------------------------------------
Function name: Alert ($C _alert, $I _goback=0)
Action: illegal Operation warning
Parameters: $C _alert (prompt error message)
$I _goback (back to that page)
return value: String
Remark: None
//--------------------------------------------------
function Alert ($C _alert, $I _goback=0)
{
if ($I _goback<>0)
{
echo "";
}
Else
{
echo "";
}
}
//--------------------------------------------------
//--------------------------------------------------
Function name: Alertexit ($C _alert, $I _goback=0)
Action: illegal Operation warning
Parameters: $C _alert (prompt error message)
$I _goback (back to that page)
return value: String
Remark: None
//--------------------------------------------------
function Alertexit ($C _alert, $I _goback=0)
{
if ($I _goback<>0)
{
echo "";
Exit
}
Else
{
echo "";
Exit
}
}
//--------------------------------------------------
//--------------------------------------------------
Function name: Replacespacialchar ($C _char)
Role: special character substitution function
Parameters: $C _char (string to be replaced)
return value: String
Remark: None
//--------------------------------------------------
function Replacespecialchar ($C _char)
{
$C _char=htmlspecialchars ($C _char); Converts special characters to HTML format.
$C _char=nl2br ($C _char); Replace the carriage return with the

$C _char=str_replace ("", "", $C _char); Replace a space with
$C _char=str_replace (" return $C _char;
}
//--------------------------------------------------
//--------------------------------------------------
Function name: Exchangemoney ($N _money)
Role: money transfer function
Parameters: $N _money (number of amounts to be converted)
return value: String
Note: Example of this function: $char =exchangemoney (5645132.3155) ==> $char = ' ¥5,645,132.31 '
//--------------------------------------------------
function Exchangemoney ($N _money)
{
$A _tmp=explode (".", $N _money); Divides a number into two parts by a decimal point and deposits it into an array $a_tmp
$I _len=strlen ($A _tmp[0]); Measure the width of the number of digits before the decimal point
if ($I _len%3==0)
{
$I _step= $I _LEN/3; As the front digit width mod 3 = 0, can be pressed, divided into $i_step
Part
}else
{
$step = ($len-$len%3)/3+1; As the front digit width mod 3! = 0, can be pressed, divided into $i_step
Part +1
}
$C _cur= "";
Convert amount numbers before decimal point
while ($I _len<>0)
{
$I _step--;
if ($I _step==0)
{
$C _cur. = substr ($A _tmp[0],0, $I _len-($I _step));
}else
{
$C _cur. = substr ($A _tmp[0],0, $I _len-($I _step)). ",";
}
$A _tmp[0]=substr ($A _tmp[0], $I _len-($I _step);
$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);
}
}
Plus the renminbi sign and out
$C _cur= "¥". $C _cur;
return $C _cur;
}
//--------------------------------------------------
//-------------------------------------------------
Function name: windowlocation ($C _url, $C _get= "", $C _getother= "")
Role: window.location function in PHP
Parameters: $C _url The URL of the Steering window
$C _get Get method parameters
$C other parameters of the _getother get method
return value: String
Remark: 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;
}
//------------------------------------------------
?>

The above describes the Thunder high-speed Channel unlimited use of PHP universal detection function set, including the Thunder High-speed Channel unlimited use of content, I hope that the PHP tutorial interested friends helpful.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.