How to use PHP form validation 3 functions isset (), Empty (), is_numeric () _php Tutorial

Source: Internet
Author: User
ISSET ();--suitable for detecting the presence of this parameter.
Definition and scope: used to test whether a variable has a value (including 0,false, or an empty string, but not null), that is: "http://localhost/?fo=" is also detectable and therefore not applicable. However, if the "http://localhost/" parameter does not contain the FO parameter, it can be detected with isset, at which point the isset ($_get[' fo ') returns false.
Not applicable: This function is not suitable for validating the text in an HTML form in an efficient way. To check whether the user input text is valid, you can use empty ();
Empty ();--The best use of a function.
Definition and scope: used to check if a variable has a null value: include: empty string, 0,null or FALSE, that is: "http://localhost/?fo=" or "http://localhost/?fo=0", Empty detection results are ture, not applicable range: not used to detect the parameters can be 0.
Is_numeric ();--only for the detection of numbers, but if the parameter name does not exist, it will be wrong, so it is not suitable for the first layer detection.
Comprehensive Example:
Copy CodeThe code is as follows:
Ini_set ("Display_errors", 1);
Ini_set ("error_reporting", E_all); Print_r
Error_reporting (E_all);
$a =null;
if (Isset ($a)) echo ' variable $ A ' isset is true ';
Echo '

Isset of the situation:

';
if (Isset ($_get[' fo ')) {
echo ' variable/' fo/' isset is true, variable available ';
}else{
echo ' variable/' fo/' Isset is false, no variable set ';
}
Echo '

Empty case:

';
if (Empty ($_get[' fo '))) {
echo ' variable/' fo/' empty is true, that is, null or invalid value ';
}else{
echo ' variable/' fo/' of empty is false, has value ';
}
Echo '

Is_numeric of the situation:

';
if (Is_numeric ($_get[' fo '))) {//There is no fo parameter in the parameter, there is an error.
echo ' variable/' fo/' is_numeric is true, is the number ';
}else{
echo ' variable/' fo/' Is_numeric is false, not a number ';
}
echo "

/$_get[' fo ']= ' case:

";
if ($_get[' fo ']== ') {//There is no fo parameter in the parameter, then an error occurs.
echo ' fo no value, empty string ';
}elseif ($_get[' fo ']!= ') {
Echo ' fo has value, not for/'. ';
}
echo "

/$_get[' sex ']= ' m ' Case:

";
if ($_get[' sex ']== ' m ') {//error occurs when there is no sex variable in the parameter.
Echo ' The man ';
}elseif ($_get[' sex ']== ' f ') {
echo ' female ';
}
?>




<title>Untitled Document</title>




Pass valid value to pass NULL value to pass 0 value



Gender: Male: Female



Empty






http://www.bkjia.com/PHPjc/324138.html www.bkjia.com true http://www.bkjia.com/PHPjc/324138.html techarticle ISSET ();--suitable for detecting the presence of this parameter. Definition and scope: used to test whether a variable has a value (including 0,false, or an empty string, but not null) ...

  • 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.