Home > Backend Development > PHP Tutorial > A function to get the content of the page

A function to get the content of the page

WBOY
Release: 2016-07-25 09:11:35
Original
979 people have browsed it
获取页面内容的一个函数
  1. function getwebdate($url){
  2. $tmp = str_replace('http://', '', $url);
  3. $domain = substr($tmp, 0, strpos($tmp, '/'));
  4. $path = strstr($tmp, '/');
  5. $fp = fsockopen($domain, 80, $errno, $errstr, 30);
  6. if (!$fp) {
  7. echo "$errstr ($errno)
    n";
  8. } else {
  9. $out = "GET $path HTTP/1.1rn";
  10. $out .= "Host: {$domain}rn";
  11. //$out .= "Referer: {$url}rn";
  12. $out .= "Connection: Closernrn";
  13. fwrite($fp, $out);
  14. while (!feof($fp)) {
  15. $html .= fgets($fp, 128);
  16. }
  17. fclose($fp);
  18. return substr(strstr($html, "rnrn"), 4);
  19. }
  20. }
复制代码


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template