一、用file_get_contents以get方式獲取內容,需要輸入內容為:
發展壯大離不開廣大客戶長期以來的信賴與支持,我們將始終秉承“誠信為本、服務至上”的服務理念,堅持“二合一”的優良服務模式,真誠服務每家企業,認真做好每個細節,不斷完善自我,成就企業,實現共贏。行業涉及咖啡廳設計等,在成都網站建設、成都全網營銷、WAP手機網站、VI設計、軟件開發等項目上具有豐富的設計經驗。
1、?php
2、$url='';
3、$html=file_get_contents($url);
4、echo$html;
5、?
二、用file_get_contents函數,以post方式獲取url,需要輸入內容為
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方式獲取內容,需要輸入內容為
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=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函數打開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
如果你要
和
之間的所有源碼,用 preg_match 就可以,不用preg_match_all ,如果你要里面的所有的
標簽中的內容,可以用preg_match_all //提取所有代碼 $pattern = '/
(.+?)
/is'; preg_match($pattern, $string, $match); //$match[0] 即為
和
之間的所有源碼 echo $match[0]; //然后再提取
之間的內容 $pattern = '/(.+?)li/is'; preg_match_all($pattern, $match[0], $results); $new_arr=array_unique($results[0]); foreach($new_arr as $kkk){ echo $kkk; }
具體實現思路是這樣的:
點擊商品詳情,獲得該商品在數據庫中的ID號,然后根據這個ID號往數據庫里面查找數據,包括使用for循環等.
分享名稱:php獲取詳情數據 php獲取系統信息
網頁鏈接:http://www.yijiale78.com/article12/hgcddc.html
成都網站建設公司_創新互聯,為您提供網站排名、網站設計、企業網站制作、全網營銷推廣、定制開發、定制網站
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯