网站首页 » 笔记 » 获取网站title,description,keywords||类文件

获取网站title,description,keywords||类文件

September 2, 2016 笔记
<?php 
$url = "http://www.ai-dianpu.com";;
/* Server IP /
function get_serverip($url)
{
    $domain&nbsp;=&nbsp;get_domain($url);
    if ($domain) {
        $ip&nbsp;=&nbsp;gethostbyname($domain);
    } else {
        $ip = 0;
    }
    return $ip;
}
/* Google Pagerank /
function get_pagerank($url)
{
    $data&nbsp;=&nbsp;get_url_content(&quot;http://pr.links.cn/getpr.asp?queryurl={$url}&show=1");
    if (preg_match('/
(\d+)<\ a="">/i', $data,&nbsp;$matches)) {
        $rank&nbsp;=&nbsp;intval($matches[2]);
    } else {
        $rank = 0;
    }
    return $rank;
}
/* Baidu Pagerank /
function get_baidurank($url)
{
    $data&nbsp;=&nbsp;get_url_content(&quot;http://www.aizhan.com/getbr.php?url={$url}&style=1");
    if (preg_match('/(\d+)<\ a="">/i', $data,&nbsp;$matches)) {
        $rank&nbsp;=&nbsp;intval($matches[2]);
    } else {
        $rank = 0;
    }
    return $rank;
}
/* Sogou Pagerank /
function get_sogourank($url)
{
    $data&nbsp;=&nbsp;get_url_content(&quot;http://rank.ie.sogou.com/sogourank.php?ur={$url}");
    if (preg_match('/sogourank=(\d+)/i', $data,&nbsp;$matches)) {
        $rank&nbsp;=&nbsp;intval($matches[1]);
    } else {
        $rank = 0;
    }
    return $rank;
}
/* Alexa Rank /
function get_alexarank($url)
{
    $data&nbsp;=&nbsp;get_url_content(&quot;http://xml.alexa.com/data?cli=10&amp;dat=nsa&amp;ver=quirk-searchstatus&amp;url={$url}");
    if (preg_match('/]URL1TEXT1*\"([0-9]+)\"/i', $data,&nbsp;$matches)) {
        $rank&nbsp;=&nbsp;strip_tags($matches[1]);
    } else {
        $rank = 0;
    }
    return $rank;
}
/* 获取客户端IP /
function get_client_ip()
{
    if (getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) {
        $client_ip = getenv('HTTP_CLIENT_IP');
    } elseif (getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown')) {
        $client_ip = getenv('HTTP_X_FORWARDED_FOR');
    } elseif (getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown')) {
        $client_ip = getenv('REMOTE_ADDR');
    } elseif (isset($_SERVER[&#39;REMOTE_ADDR&#39;])&nbsp;&amp;&amp;&nbsp;$_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) {
        $client_ip&nbsp;=&nbsp;$_SERVER['REMOTE_ADDR'];
    }
    $client_ip&nbsp;=&nbsp;addslashes($client_ip);
    @preg_match("/[\d\.]{7,15}/", $client_ip,&nbsp;$ip);
    $ip_addr&nbsp;=&nbsp;$ip[0] ? $ip[0] : 'unknown';
    unset($ip);
    return $ip_addr;
}
function get_domain($url)
{
    if (preg_match("/^(http:\/\/)?(2+)/i", $url,&nbsp;$domain)) {
        return $domain[2];
    } else {
        return false;
    }
}
function format_url($url)
{
    if ($url != "") {
        $url_parts&nbsp;=&nbsp;parse_url($url);
        $scheme&nbsp;=&nbsp;$url_parts['scheme'];
        $host&nbsp;=&nbsp;$url_parts['host'];
        $path&nbsp;=&nbsp;$url_parts['path'];
        $port&nbsp;=&nbsp;!empty($url_parts['port']) ? ':' . $url_parts['port'] : '';
        $url&nbsp;=&nbsp;(!empty($scheme) ? $scheme&nbsp;.&nbsp;&#39;://&#39;&nbsp;.&nbsp;$host : (!empty($host)&nbsp;?&nbsp;&#39;http://&#39;&nbsp;.&nbsp;$host : 'http://'; . $path))&nbsp;.&nbsp;$port . '/';
        return $url;
    }
}
/* 获取指定URL内容 /
function get_url_content($url)
{
    if (empty($url)) {
        return false;
    }
    if (substr($url, 0, 7) != 'http://';) {
        $url&nbsp;=&nbsp;&#39;http://&#39;&nbsp;.&nbsp;$url;
    }
    $timeout = 30;
    $data = '';
    for ($i&nbsp;=&nbsp;0;&nbsp;$i < 5 && empty($data);&nbsp;$i++) {
        if (function_exists('curl_init')) {
            $ch = curl_init();
            curl_setopt($ch,&nbsp;CURLOPT_URL,&nbsp;$url);
            curl_setopt($ch,&nbsp;CURLOPT_TIMEOUT,&nbsp;$timeout);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0');
            $data&nbsp;=&nbsp;curl_exec($ch);
            $http_code&nbsp;=&nbsp;curl_getinfo($ch, CURLINFO_HTTP_CODE);
            if ($http_code != '200') {
                return false;
            }
        } elseif (function_exists('fsockopen')) {
            $params&nbsp;=&nbsp;parse_url($url);
            $host&nbsp;=&nbsp;$params['host'];
            $path&nbsp;=&nbsp;$params['path'];
            $query&nbsp;=&nbsp;$params['query'];
            $fp&nbsp;=&nbsp;@fsockopen($host, 80, $errno,&nbsp;$errstr, $timeout);
            if (!$fp) {
                return false;
            } else {
                $result = '';
                $out&nbsp;=&nbsp;&quot;GET&nbsp;/&quot;&nbsp;.&nbsp;$path . '?' . $query . " HTTP/1.0rn";
                $out&nbsp;.=&nbsp;&quot;Host:&nbsp;{$host}rn";
                $out .= "Connection: Closernrn";
                @fwrite($fp,&nbsp;$out);
                $http_200&nbsp;=&nbsp;preg_match(&#39;/HTTP.*200/&#39;,&nbsp;@fgets($fp, 1024));
                if (!$http_200) {
                    return false;
                }
                while (!@feof($fp)) {
                    if ($get_info) {
                        $data&nbsp;.=&nbsp;@fread($fp, 1024);
                    } else {
                        if (@fgets($fp, 1024) == "rn") {
                            $get_info = true;
                        }
                    }
                }
                @fclose($fp);
            }
        } elseif (function_exists('file_get_contents')) {
            if (!get_cfg_var('allow_url_fopen')) {
                return false;
            }
            $context&nbsp;=&nbsp;stream_context_create(array(&#39;http&#39;&nbsp;=&gt;&nbsp;array(&#39;timeout&#39;&nbsp;=&gt;&nbsp;$timeout)));
            $data&nbsp;=&nbsp;@file_get_contents($url, false, $context);
        } else {
            return false;
        }
    }
    if (!$data) {
        return false;
    } else {
        $encode&nbsp;=&nbsp;mb_detect_encoding($data, array('ascii', 'gb2312', 'utf-8', 'gbk'));
        if ($encode&nbsp;==&nbsp;&#39;EUC-CN&#39;&nbsp;||&nbsp;$encode == 'CP936') {
            $data&nbsp;=&nbsp;@mb_convert_encoding($data, 'utf-8', 'gb2312');
        }
        return $data;
    }
}
<p><br/></p>

  1. >
  2. \/
Title - Artist
0:00