php接受通過HTML表單提交的信息時,會將提交的數(shù)據(jù)保存在全局數(shù)組中,我們可以調用系統(tǒng)特定的自動全局變量數(shù)組來獲取這些值。
常用的自動全局變量如下所示:
1、GET方式
功能:獲取get方式提交的數(shù)據(jù)
格式:$_GET[“formelement”]
2、POST方式
功能:獲取post方式提交的數(shù)據(jù)
格式:$_POST[“formelement”]
3、REQUEST方式
功能:獲取任意方式提交的數(shù)據(jù),$_REQUEST自動全局變量包含了所有GET、POST、COOKIE和FILE的數(shù)據(jù),如不關心數(shù)據(jù)來源。
格式:$_REQUEST[“formelement”]
復選框 、列表框(名稱采用數(shù)組形式如:"select[]",在獲取其值的時候直接使用$_POST["select"]即可)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
<!doctype html> <html> <head> <meta charset= "utf-8" > <title>無標題文檔</title> </head> <body> <!--獲取表單數(shù)據(jù)的兩種方法--> <!--post--> <form method= "post" action= "8.3.php" name= "form1" > <table border= "1" width= "400" cellpadding= "0" cellspacing= "0" > <tr> <td height= "30" > 用戶名:<input name= "txtName" type= "text" size= "12" > 密碼:<input name= "txtPsd" type= "password" size= "12" > <input type= "submit" name= "SubmitBtn" value= "提交" > </td> </tr> </table> </form><br/> <!--get URL的長度需要限定在1M范圍內,否則會截取--> <!--可以使用urlencode與urldecode對URL進行編解碼--> <form method= "get" action= "8.3.php" name= "form2" > <table border= "1" width= "400" cellpadding= "0" cellspacing= "0" > <tr> <td width= "400" height= "30" > 訂單號:<input name= "txtFrame" type= "text" size= "12" > <input type= "submit" name= "SubmitBtn" > </td> </tr> </table> </form> <!--在Web頁面中嵌入PHP腳本--> <?php $strTxt = '男' ; ?> <input type= "text" value= "<?php echo " strTxt "; ?>" > </body> <?php echo '用戶名: ' . $_POST [ "txtName" ]. " 密碼:" . $_POST [ 'txtPsd' ]; echo '訂單號:' . $_GET [ "txtFrame" ]; ?> </html> |
以上這篇PHP獲取表單數(shù)據(jù)與HTML嵌入PHP腳本的實現(xiàn)就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持服務器之家。