获取页面内容的一个函数
时间:2021-07-01 10:21:17
帮助过:15人阅读
获取页面内容的一个函数
- function getwebdate($url){
- $tmp = str_replace('http://', '', $url);
- $domain = substr($tmp, 0, strpos($tmp, '/'));
- $path = strstr($tmp, '/');
- $fp = fsockopen($domain, 80, $errno, $errstr, 30);
- if (!$fp) {
- echo "$errstr ($errno)
\n"; - } else {
- $out = "GET $path HTTP/1.1\r\n";
- $out .= "Host: {$domain}\r\n";
- //$out .= "Referer: {$url}\r\n";
- $out .= "Connection: Close\r\n\r\n";
-
- fwrite($fp, $out);
- while (!feof($fp)) {
- $html .= fgets($fp, 128);
- }
- fclose($fp);
- return substr(strstr($html, "\r\n\r\n"), 4);
- }
- }
|