新聞中心
PHP怎么獲取表單提交的數(shù)據(jù)???
一、用file_get_contents以get方式獲取內(nèi)容,需要輸入內(nèi)容為:
創(chuàng)新互聯(lián)專注于企業(yè)全網(wǎng)營銷推廣、網(wǎng)站重做改版、本溪網(wǎng)站定制設(shè)計、自適應(yīng)品牌網(wǎng)站建設(shè)、H5高端網(wǎng)站建設(shè)、商城網(wǎng)站制作、集團公司官網(wǎng)建設(shè)、外貿(mào)網(wǎng)站建設(shè)、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁設(shè)計等建站業(yè)務(wù),價格優(yōu)惠性價比高,為本溪等各大城市提供網(wǎng)站開發(fā)制作服務(wù)。
1、?php
2、$url='';
3、$html=file_get_contents($url);
4、echo$html;
5、?
二、用file_get_contents函數(shù),以post方式獲取url,需要輸入內(nèi)容為
1、?php
2、$url='';
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方式獲取內(nèi)容,需要輸入內(nèi)容為
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方式獲取內(nèi)容,需要輸入內(nèi)容為
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=c3;cook2=c4\r\n".
8、"Content-Length:".strlen($data)."\r\n",
9、'content'=$data
10、)
11、);
12、$context=stream_context_create($opts);
13、$html=fopen(';id2=i4','rb',false,$context);
14、$w=fread($html,1024);
15、echo$w;
16、?
五、用fsockopen函數(shù)打開url,以get方式獲取完整的數(shù)據(jù),包括header和body,需要輸入內(nèi)容為
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
快遞100 php接口顯示結(jié)果是這個,但是無法顯示物流信息,為什么?
快遞100免費的是頁面嵌入的方式,不是直接給物流數(shù)據(jù)的,直接的物流數(shù)據(jù)包要收費??爝f鳥接口是免費直接數(shù)據(jù)傳輸?shù)膥
php中怎么直接獲取post數(shù)據(jù)
方法1、最常見的方法是:$_POST['fieldname'];
說明:只能接收Content-Type: application/x-www-form-urlencoded提交的數(shù)據(jù)
解釋:也就是表單POST過來的數(shù)據(jù)
方法2、file_get_contents("php://input");
說明:
允許讀取 POST 的原始數(shù)據(jù)。
和 $HTTP_RAW_POST_DATA 比起來,它給內(nèi)存帶來的壓力較小,并且不需要任何特殊的 php.ini 設(shè)置。
php://input 不能用于 enctype="multipart/form-data"。
解釋:
對于未指定 Content-Type 的POST數(shù)據(jù),則可以使用file_get_contents(“php://input”);來獲取原始數(shù)據(jù)。
事實上,用PHP接收POST的任何數(shù)據(jù)都可以使用本方法。而不用考慮Content-Type,包括二進制文件流也可以。
所以用方法二是最保險的方法
php獲取post數(shù)據(jù)
方法1、最常見的方法是:$_post['fieldname'];
說明:只能接收content-type:
application/x-www-form-urlencoded提交的數(shù)據(jù)
解釋:也就是表單post過來的數(shù)據(jù)
方法2、file_get_contents("php://input");
說明:
允許讀取
post
的原始數(shù)據(jù)。
和
$http_raw_post_data
比起來,它給內(nèi)存帶來的壓力較小,并且不需要任何特殊的
php.ini
設(shè)置。
php://input
不能用于
enctype="multipart/form-data"。
解釋:
對于未指定
content-type
的post數(shù)據(jù),則可以使用file_get_contents(“php://input”);來獲取原始數(shù)據(jù)。
事實上,用php接收post的任何數(shù)據(jù)都可以使用本方法。而不用考慮content-type,包括二進制文件流也可以。
所以用方法二是最保險的方法
方法3、$globals['http_raw_post_data'];
說明:
總是產(chǎn)生
$http_raw_post_data
變量包含有原始的
post
數(shù)據(jù)。
此變量僅在碰到未識別
mime
類型的數(shù)據(jù)時產(chǎn)生。
$http_raw_post_data
對于
enctype="multipart/form-data"
表單數(shù)據(jù)不可用
如果post過來的數(shù)據(jù)不是php能夠識別的,可以用
$globals['http_raw_post_data']來接收,
比如
text/xml
或者
soap
等等
解釋:
$globals['http_raw_post_data']存放的是post過來的原始數(shù)據(jù)。
$_post或$_request存放的是
php以key=value的形式格式化以后的數(shù)據(jù)。
但$globals['http_raw_post_data']中是否保存post過來的數(shù)據(jù)取決于centent-type的設(shè)置,即post數(shù)據(jù)時
必須顯式示指明content-type:
application/x-www-form-urlencoded,post的數(shù)據(jù)才會存放到
$globals['http_raw_post_data']中
網(wǎng)頁標題:php獲取快遞數(shù)據(jù) php獲取快遞數(shù)據(jù)的方法
當前地址:http://fisionsoft.com.cn/article/dodppop.html