7)get方式提交表单和简单处理

一个带有html的代码:   hello.php

 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 2 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-cn">
 3 <head>
 4     <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
 5     <title>网页标题</title>
 6     <meta name="keywords" content="关键字列表" />
 7     <meta name="description" content="网页描述" />
 8     <link rel="stylesheet" type="text/css" href="" />
 9     <style type="text/css"></style>
10     <script type="text/javascript"></script>
11 </head>
12 <body>
13     <form  action="c.php"  method="get" >
14         项目1: <input type="text"   name="uName"   />
15         项目2: <input type="password"   name="uPswd"   />
16         项目3: <input type="text"   name="age"   />
17         <br />
18         爱好:
19             <input type="checkbox" name="hobby[]" value="足球" />足球
20             <input type="checkbox" name="hobby[]" value="篮球" />篮球
21             <input type="checkbox" name="hobby[]" value="中国足球" />中国足球
22         <br />
23         <input type="submit"  value="提交"  />
24     </form>
25     <hr />
26     <a  href="4get_2.php?uName=test1&uPswd=123"  > 文字。。。</a>
27 </body>
28 </html>

然后就是处理代码:  c.php

 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 2 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-cn">
 3 <head>
 4     <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
 5     <title>网页标题</title>
 6     <meta name="keywords" content="关键字列表" />
 7     <meta name="description" content="网页描述" />
 8     <link rel="stylesheet" type="text/css" href="" />
 9     <style type="text/css"></style>
10     <script type="text/javascript"></script>
11 </head>
12 <body>
13 <?php
14 $v1 = $_GET['uName'];        
15 //单引号也可以用双引号,本质是一个字符串,其实是数组的键名(下标)
16 
17 $v2 = $_GET["uPswd"];        
18 //该键名必须跟提交的时候的名字完全一致(区分大小写)
19 
20 echo "v1=$v1, v2=$v2";
21 echo "<hr />";
22 echo "<pre>";
23 var_dump($_GET);    //var_dump()用于输出一个变量的“最完整信息”
24                     //(包括变量名,变量数据值,变量长度(如果有)
25                     //这里是在试图输出$_GET这个“数组”;
26 echo "</pre>";
27 
28 //理解:
29 
30 ?>
31 </body>
32 </html>
或者这么写:

1
var_dump( $_GET);


显示结果是:
D:\00-Code\PhpStorm\Demo\demo01\c.php:10:
array (size=4)
  'uName' => 
string
 'root' (length=4)
  'uPswd' => 
string
 'wangchao12' (length=10)
  'age' => 
string
 'gdg' (length=3)
  'hobby' => 
    array (size=1)
      0 => 
string
 '足球' (length=6)

 

posted @ 2017-08-08 15:01  小油菜1  阅读(258)  评论(0编辑  收藏  举报