CSDN博客

img bjbs_270

一个函数

发表于2004/10/9 9:08:00  1311人阅读


function GetHTML ($url, &$delta, $corto = false, $complet = true) {

  
$url_stuff = parse_url($url);

  
$fp = fsockopen ($url_stuff['host'], 80, $errno, $errstr, 30);

  if (!
$fp) {

   exit;

  } else {
   
$header = "GET " . $url_stuff['path'] . "?" . $url_stuff['query'] ;

   
$header = $header . " HTTP/1.0/r/nHost: " . $url_stuff['host'] . "/r/n/r/n";

   
fputs ($fp, $header);

   
//Separar contenido...

   
$header = '';

   
$body = '';

   
$act = false;

   
$fin = false;

   while ((!
feof($fp)) && !$fin) {

       
$line = fgets ($fp,1024);

       if (!
$act) {

         if (
strpos($line, "/r/n", 0) == 0) {

           
$header .= $line;

           if (!
$complet) $fin = true;

             
$act = true;

           } else {

             
$header .= $line;

           }

         } else {

         if (
$corto) {

           if (
eregi ("<body([^>]*)>", $line, $o)) $fin = true;

         }

         if (!
$fin) $body = $body . $line;

       }

   }

       

   
//Seguir location...

   
$ret = strpos($header, "Location:", 0);

     if (
$ret !== false) {

     
$fin = strpos($header, "/r/n", $ret +9);

     
$nueva = substr($header, $ret+9, $fin - $ret - 9);

     
$body = GetHTML($nueva, $delta, $corto, $complet);

     } else {

     
$delta = $url;

   }



   
fclose ($fp);

}



return
$body;

}

阅读全文
0 0

相关文章推荐

img
取 消
img