PHP基础:预定义变量

对有编程经验,但新入手web编程的人来说,先熟悉预定义变量的用法是个比较好的方式。
一、学习途径:
PHP手册->语言参考->预定义变量
1. $_POST
把里面的例子做一遍,很有好处。

ex1:

telconstar99 at hotnospampleasemail dot com (20-May-2008 08:49)

 1 <?
 2 
 3 //If we submitted the form
 4 if(isset($_POST['submitMe']))
 5 {
 6      echo("Hello, " . $_POST['name'] . ", we submitted your form!");
 7 }
 8 //If we haven't submitted the form
 9 else
10 {
11 ?>
12     <form action="<?=$_SERVER['PHP_SELF']?>" method="POST">
13     <input type="text" name="name"><br>
14     <input type="submit" value="submit" name="submitMe">
15     </form>
16 <?
17 }
18 ?>

 1个知识点:

(1) 第12行,$_SERVER['PHP_SELF'],表示当前执行脚本的文件名,如test.php。

可见,先熟悉掌握预定义变量很有用。

 ex2:

php dot net at bigbadaboom dot net (15-Jul-2008 04:06)

 1 <input type="submit" name="submit">
 2 
 3 isset($_POST["submit"]) returns false
 4 
 5 <input type="submit" name="submit" value="Next">
 6 
 7 isset($_POST["submit"]) returns true.
 8 
 9 This might seem obvious for text buttons since they need a label anyway.  However, if you are using image buttons, it might not occur to you that you need to set a value attribute as well.  For example, the value attribute is required in the following element if you want to be able to detect it in your script.
10 
11 <input type="image" name="submit" src="next.gif" value="Next"> 

一个知识点:

如果在input里遗漏value的值,$_POST["submit"]将为null。

写程序是个细心的经验活,今天根据手册做了几个例子,对基本知识点有了更清楚的认识。有收获。

 

 
 

posted on 2012-06-03 22:12  闲时  阅读(97)  评论(0)    收藏  举报

导航