Php retrieves page content
Php retrieves page content
Method 1: Use file_get_contents to get the content in get mode.
Method 2: Use the file_get_contents function to obtain the url in post mode.
'Bar'); $ data = http_build_query ($ data); $ opts = array ('http' => array ('method' => 'post ', 'header' => "Content-type: application/x-www-form-urlencoded \ r \ n ". "Content-Length :". strlen ($ data ). "\ r \ n", 'content' => $ data); $ ctx = stream_context_create ($ opts); $ html = @ file_get_contents ($ url ,'', $ ctx); if you need to transmit cookie data, set 'header' => "Content-type: application/x-www-form-urlencoded \ r \ n ". "Content-Length :". strlen ($ data ). "\ r \ n", changed to 'header' => "Content-type: application/x-www-form-urlencoded \ r \ n ". "Content-Length :". strlen ($ data ). "\ r \ n ". "cookie: cookie1 = c1; cookie2 = c2 \ r \ n"; Method 3: use fopen to open the url and get the content
": Echo" url body: $ result "; fclose ($ fp);?> Method 4: use fopen to open the url and obtain the content in post mode.
'Bar2', 'foo3' => 'bar3'); $ data = http_build_query ($ data ); $ opts = array ('http' => array ('method' => 'post', 'header' => "Content-type: application/x-www-form-urlencoded \ r \ nCookie: cook1 = c3; cook2 = c4 \ r \ n ". "Content-Length :". strlen ($ data ). "\ r \ n", 'content' => $ data); $ context = stream_context_create ($ opts); $ html = fopen ('http: // www.test.com/zzzzzz.php? Id = i3 & id2 = I4', 'RB', false, $ context); $ w = fread ($ html, 1024); echo $ w;?> Method 5: Use the fsockopen function to open the url and get the complete data, including the header and body.
Method 6: Use the fsockopen function to open the url and obtain the complete data in POST mode, including the header and body.
$ Value) $ values [] = "$ key = ". urlencode ($ value); $ data_string = implode ("&", $ values); // Find out which port is needed-if not given use standard (= 80) if (! Isset ($ URL_Info ["port"]) $ URL_Info ["port"] = 80; // building POST-request: $ request. = "POST ". $ URL_Info ["path"]. "HTTP/1.1 \ n"; $ request. = "Host :". $ URL_Info ["host"]. "\ n"; $ request. = "Referer: $ referer \ n"; $ request. = "Content-type: application/x-www-form-urlencoded \ n"; $ request. = "Content-length :". strlen ($ data_string ). "\ n"; $ request. = "Connection: close \ n"; $ request. = "Cookie: $ cookie \ n"; $ request. = "\ n"; $ Request. = $ data_string. "\ n"; $ fp = fsockopen ($ URL_Info ["host"], $ URL_Info ["port"]); fputs ($ fp, $ request); while (! Feof ($ fp) {$ result. = fgets ($ fp, 1024) ;}fclose ($ fp); return $ result ;}?> Method 7: Use the curl Library. before using the curl library, you may need to check whether php. ini has enabled the curl extension.
The above is the page content obtained by php. For more information, see PHP Chinese website (www.php1.cn )!