note 36640 deleted from features.remote-files by nlopess

From: Date: Wed, 16 Mar 2005 15:15:35 +0000
Subject: note 36640 deleted from features.remote-files by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-86557@lists.php.net to get a copy of this message
Note Submitter: webmaster at elcurriculum dot com ---- This function get HTML source from url. Follow all locations to last site. Ideal for Search Engine. $url = web site to explore. $delta = last url from location $corto = if corto is true stop function when the tag is <body>. (This is for get metatags and title). $complet = if complet is true return all body of page. Else return only $delta. (This is for get redirect from image: <img src=http://www.solobanner.com/index.php>) <?php 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; } // Example: $url = "http://www.elcurriculum.com/banner/go.php?from=1&to26"; echo GetHTML($url,$a,true); echo "<br>Go to url: $a"; ?> By Tryke. (Jose María Rodríguez Valls). http://www.elcurriculum.com http://www.solobanners.com

« previous php.notes (#86557) next »