Home  >  Article  >  php教程  >  php $_POST[]获取表单数据方法

php $_POST[]获取表单数据方法

WBOY
WBOYOriginal
2016-05-25 16:46:261595browse

在php获取表单数据有专用的命令,$_POST[]就是这个函数了,下面来看我们一个简单的实例:

输出是来自表单的first_name的值,再看一个复杂一点点的实例:

$_POST['name'] = trim($_POST['name']); 
	 
	if (strlen($_POST['name']) == 0) { 
	    $errors[] = "Your name is required."; 
	} 

好了,下面做一个关于$_POST的完整实例:

 class="brush:php;"> 
	  
	  Set Cookie Data 
	 
Please enter your first name:

Please choose your favorite font color:
Red Green Blue

总结:上面的实例没做安全处理,只是简单的获取了表单提交的数据,我们可以做一些安全处理,如isset() addslashes 等处理.

本文地址:

转载随意,但请附上文章地址:-)

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn