PHP ???? ?? ??
1.php ??
PHP ??? ??? ??? ?? ??? ??? ???? ???? ????? ? ?????.
2. PHP ???
PHP ??? ???? ?? ??? ???? ???? ????? ? ?????.
??? ?? ?? ?? ???? ????? ???? ????? ?? ?? ? ???????? ??? ?????. PHP? ?? ??? ??? ???? ? ?? ??? ???? ???????
3. ??? ???? ??
?? ?? ? ??????? ?? ??? ?????. ? ???? ????? ??? ?? ?? ??????(?: ? ???)?? ?????. ??? ???? ??????? ??? ?? ??? ??? ? ? ????
?? ???? ????? ??? ?????, ?? ?? ???? ????
(1).???? ??? ??
(2).??
(3).? ??? ???
(4).?? ??
(5). ?????? ?? ??
?? ? ??
??? ?????? ?? ? ??? ?????. ?? ??:
filter_var() - ??? ??? ?? ?? ???
filter_var_array() - ????? ?? ??? ?? ?? ??? ??
filter_input - ?? ??? ???? ??????.
filter_input_array - ?? ?? ??? ???? ????? ?? ??? ??????.
<?php header("Content-type: text/html; charset=utf-8");//設(shè)置編碼 $int = 123; if(!filter_var($int, FILTER_VALIDATE_INT)){ echo("不是一個(gè)合法的整數(shù)"); }else{ echo("是個(gè)合法的整數(shù)"); } ?>
??: ??? ??? ?? ??? ??? ????. ??? ?? ?? ??? ??? ??? ????.
?? ? ?? ? ?? ??? ??? ????.
?? ??:
??? ??? ???? ? ?????.
??? ?? ??(?: URL ?? ??? ??)
??? ?? ?? ??? ????? ?? ? FALSE? ?????.
?? ?? :
????? ??? ??? ????? ???? ?? ? ?????.
??? ?? ?? ??
?? ???? ?????.
?? ? ???
??? ???? ??? ??? ?? ??? ??? ???? ? ?????.
???? ??? ???? ????
<?php header("Content-type: text/html; charset=utf-8");//設(shè)置編碼 $var=300; $int_options = array( "options"=>array( "min_range"=>0, "max_range"=>256 ) ); if(!filter_var($var, FILTER_VALIDATE_INT, $int_options)){ echo("不是一個(gè)合法的整數(shù)"); }else{ echo("是個(gè)合法的整數(shù)"); } ?>
??: ?? ??? ????? ??? "options"?? ?? ??? ??? ???. ???? ???? ?? ??? ?? ??? ????. ??? "300"??? ??? ??? ??? ????.
?? ??? ??
?? ???? ??? ?????. ???? ??????.
?? ?? ?? ? ?? ?? ?? ?? ???? ????? ???? ????.
?? ?? filter_input() ??? ???? ?? ???? ??????.
?? ???? ?? ?? "email"? PHP ???? ?????.
<?php header("Content-type: text/html; charset=utf-8");//設(shè)置編碼 if(!filter_has_var(INPUT_GET, "email")){ echo("沒有 email 參數(shù)"); }else{ if (!filter_input(INPUT_GET, "email", FILTER_VALIDATE_EMAIL)){ echo "不是一個(gè)合法的 E-Mail"; }else{ echo "是一個(gè)合法的 E-Mail"; } } ?>
??: ???? ???? ??? ? ?? get? ?? ??? ???? ??? ?????
?? ???? ???? ???? ????? ???? ???
?? ??
???? ??? URL? ??? ?????.
?? ??? ?? ?? ?? ???? ????? ???? ????.
?? ?? filter_input() ??? ???? ?? ???? ?????.
?? ???? ?? ?? "url"? PHP ???? ?????.
<?php header("Content-type: text/html; charset=utf-8");//設(shè)置編碼 if(!filter_has_var(INPUT_GET, "url")){ echo("沒有 url 參數(shù)"); }else{ $url = filter_input(INPUT_GET, "url", FILTER_SANITIZE_URL); echo $url; } ?>
??: "GET" ?? "url" ?? ??? ??? ?????.
? ?? ??? ???? ?? ?? ????(?? ?? ??) $url ??? ?????.