ISSET (); -- this parameter is suitable for detecting whether this parameter exists.
Definition and scope of action: used to test whether a variable has a value (including 0, FALSE, or an empty string, but cannot be NULL), that is, "http: // localhost /? Fo = "can also pass detection, so it is not applicable. However, if the "http: // localhost/" parameter does not contain the fo parameter, you can use isset for detection. In this case, isset ($ _ GET ['fo']) returns false.
Not applicable: this function is not suitable for verifying text in html forms. To check whether the user input text is valid, you can use empty ();
Empty (); -- the best function.
Definition and scope of action: used to check whether a variable has a null value, including: null String, 0, null, or false, that is, "http: // localhost /? Fo = "or" http: // localhost /? When fo = 0 ", empty detects true and does not apply to values: 0.
Is_numeric (); -- this parameter is only applicable to the detection of numbers. If the parameter name does not exist, an error occurs. Therefore, it is not suitable for the first-level detection.
Comprehensive example:
Copy codeThe Code is 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 'isset of variable $ a' is true ';
Echo 'If (isset ($ _ GET ['fo']) {
Echo 'isset of variable \ 'fo \ 'is true and the variable is usable ';
} Else {
The isset of echo 'variable \ 'fo \ 'is false and has no variable settings ';
}
Echo 'If (empty ($ _ GET ['fo']) {
Echo 'empty of variable \ 'fo \ 'is true, that is, null or invalid value ';
} Else {
The empty of echo 'variable \ 'fo \ 'is false and has a value ';
}
Echo 'If (is_numeric ($ _ GET ['fo']) {// if the parameter does not contain the fo parameter, an error occurs.
The is_numeric of echo 'variable \ 'fo \ 'is true, a number ';
} Else {
Is_numeric of echo 'variable \ 'fo \ 'is false, not a number ';
}
Echo "
If ($ _ GET ['fo'] = '') {// if the parameter does not contain the fo parameter, an error occurs.
Echo 'fo no value, empty string ';
} Elseif ($ _ GET ['fo']! = ''){
Echo 'fo has a value, not \'\'.';
}
Echo "
If ($ _ GET ['sex '] = 'M') {// an error occurs when no sex variable exists in the parameter.
Echo 'mal ';
} Elseif ($ _ GET ['sex'] = 'F '){
Echo 'femal ';
}
?>
Copy codeThe Code is as follows:
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Title> untitled document </title>
</Head>
<Body>
</Body>
<P>
<A href = "? Fo = Jack "> pass valid values </a> <a href = "? Fo = "> pass null values </a> <a href = "? Fo = 0 "> 0 </a>
<Br/>
<A href = "? Sex = m "> Gender: male </a> <a href = "? Sex = f "> Gender: female </a>
<Br/>
<A href = "/"> clear </a>
<Br/>
<Input type = "text" value = "<? Php echo $ _ GET ['fo']! = ''? $ _ GET ['fo']: '';?> "Size =" 155 "type =" option "text =" option "/> </p type =" option "text ="/option ">
</Html>