PHP form Verification of 3 functions Isset (), Empty (), Is_numeric () method of use _php tips

Source: Internet
Author: User
Tags html form php form
ISSET ();--suitable for detecting the existence 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=" can also be detected and therefore does not apply. However, if the "http://localhost/" parameter does not contain the FO parameter, it can be detected with isset, at which point Isset ($_get[' fo ') returns false.
does not apply to: This function is not suitable for validating text in an HTML form. To check whether the user input text is valid, you can use empty ();
Empty ();-a function that is best used.
Definition and scope: used to check whether a variable has a null value: include: null string, 0,null or FALSE, namely: "http://localhost/?fo=" or "http://localhost/?fo=0", Empty detected results are ture, do not apply to the scope: does not apply to detect can be 0 parameters.
Is_numeric ();--Applies only to the number of detections, but if the parameter name does not exist, there will be an error, so it is not suitable for first-level detection.
Comprehensive Example:
Copy Code code as follows:

<?php
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 ' if (Isset ($_get[' fo ')) {
echo ' variable/' fo/' isset for true, variable available ';
}else{
echo ' variable/' fo/' isset is false, without variable setting ';
}
Echo ' if (Empty ($_get[' fo ')) {
The empty of the echo ' variable/' fo/' is true, i.e. null or void value ';
}else{
echo ' variable/' fo/' empty is false, has value ';
}
Echo ' if (Is_numeric ($_get[' fo ')) {///If there is no fo parameter in the argument, an error occurs.
The echo ' variable/' fo/' is_numeric is true, is the number ';
}else{
The echo ' variable/' fo/' Is_numeric is false, not a number ';
}
The case:echo ' fo no value, empty string ';
}elseif ($_get[' fo ']!= ') {
Echo ' fo has value, not for/'/'. '
}
The case of echo "if ($_get[' sex ']== ' m ') {///when there is no sex variable in the argument, an error occurs.
echo ' man ';
}elseif ($_get[' sex ']== ' f ') {
echo ' woman ';
}
?>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<title> Untitled Document </title>
<body>
</body>
<p>
<a href= "? fo=jack" > Valid value </a> <a href= "? fo=" > Null value </a> <a href= "? fo=0" > 0 value </a>
<br/><br/>
<a href= "sex=m" > Sex: Male </a> <a href= "sex=f" > Gender: Female </a>
<br/><br/>
<a href= "/" > Empty </a>
<br/><br/>
<input type= "text" value= "<?php echo $_get[' fo ']!= '" $_get[' fo ']: ';? > "size="/>
</p>

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.