PHP怎么获取表单提交的数据啊?

Python031

PHP怎么获取表单提交的数据啊?,第1张

一、用file_get_contents以get方式获取内容,需要输入内容为:

1、<?php

2、$url='http://www.domain.com/?para=123'

3、$html=file_get_contents($url)

4、echo$html

5、?>

二、用file_get_contents函数,以post方式获取url,需要输入内容为

1、<?php

2、$url='http://www.domain.com/test.php?id=123'

3、$data=array('foo'=>'bar')

4、$data=http_build_query($data)

5、$opts=array(

6、'http'=>array(

7、 'method'=>'POST',

8、 'header'=>"Content-type:application/x-www-form-urlencoded\r\n".

9、          "Content-Length:".strlen($data)."\r\n",

10、 'content'=>$data

11、)

12、)

13、$ctx=stream_context_create($opts)

14、$html=@file_get_contents($url,'',$ctx)

15、?>

三、用fopen打开url,以get方式获取内容,需要输入内容为

1、<?php

2、$fp=fopen($url,'r')

3、$header=stream_get_meta_data($fp)//获取信息

4、while(!feof($fp)){

5、$result.=fgets($fp,1024)

6、}

7、echo"urlheader:{$header}<br>":

8、echo"urlbody:$result"

9、fclose($fp)

10、?>

四、用fopen打开url,以post方式获取内容,需要输入内容为

1、<?php

2、$data=array('foo2'=>'bar2','foo3'=>'bar3')

3、$data=http_build_query($data)

4、$opts=array(

5、'http'=>array(

6、'method'=>'POST',

7、'header'=>"Content-type:application/x-www-form-urlencoded\r\nCookie:cook1=c3cook2=c4\r\n".

8、"Content-Length:".strlen($data)."\r\n",

9、'content'=>$data

10、)

11、)

12、$context=stream_context_create($opts)

13、$html=fopen('http://www.test.com/zzzz.php?id=i3&id2=i4','rb',false,$context)

14、$w=fread($html,1024)

15、echo$w

16、?>

五、用fsockopen函数打开url,以get方式获取完整的数据,包括header和body,需要输入内容为

1、?php

2、functionget_url($url,$cookie=false)

3、{

4、$url=parse_url($url)

5、$query=$url[path]."?".$url[query]

6、echo"Query:".$query

7、$fp=fsockopen($url[host],$url[port]?$url[port]:80,$errno,$errstr,30)

8、if(!$fp){

9、returnfalse

10、}else{

11、$request="GET$queryHTTP/1.1\r\n"

12、$request.="Host:$url[host]\r\n"

13、$request.="Connection:Close\r\n"

14、if($cookie)$request.="Cookie:  $cookie\n"

15、$request.="\r\n"

16、fwrite($fp,$request)

17、while(!@feof($fp)){

18、$result.=@fgets($fp,1024)

19、}

20、fclose($fp)

21、return$result

22、}

23、}

24、//获取url的html部分,去掉header

25、functionGetUrlHTML($url,$cookie=false)

26、{

27、$rowdata=get_url($url,$cookie)

28、if($rowdata)

29、{

30、$body=stristr($rowdata,"\r\n\r\n")

31、$body=substr($body,4,strlen($body))

32、return$body

33、}

34、 returnfalse

35、}

36、?>

参考资料:

php-file_get_contents

在PHP中可以使用魔术方法 __CLASS__ 来获取类名

官方文档如下

如果想要得到不包含类的作用域的名称或类的作用域则需要下面两个函数

类包含作用域的名称

类作用域的名称

类不包含作用域的名称

方法:

1、进入php源程序目录中的ext目录中,这里存放着各个扩展模块的源代码,选择需要的模块,比如curl模块执行phpize生成编译文件,phpize在PHP安装目录的bin目录下。

2、phpize 运行时,可能会报错Cannot find autoconf。

3、需要安装autocon执行这个命令时,php会去检查配置文件是否正确,如果有配置错误,这里会报错,可以根据错误信息去排查。