最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

php實現(xiàn)專業(yè)獲取網(wǎng)站SEO信息類實例

 更新時間:2015年04月02日 15:32:37   作者:pythoner  
這篇文章主要介紹了php實現(xiàn)專業(yè)獲取網(wǎng)站SEO信息類,實例分析了seoreport類針對網(wǎng)站SEO信息檢查與獲取的技巧,非常具有實用價值,需要的朋友可以參考下

本文實例講述了php實現(xiàn)專業(yè)獲取網(wǎng)站SEO信息類。分享給大家供大家參考。具體如下:

這個seo類的功能包括:
- 檢查指定的網(wǎng)站響應
- 獲取從該網(wǎng)站主頁的語言和其他meta標簽數(shù)據(jù)的
- 獲取網(wǎng)站的導入鏈接,從Alexa的流量排名
- 獲取網(wǎng)站的導入鏈接,由谷歌索引的網(wǎng)頁數(shù)量
- 獲取網(wǎng)站的信任,從WOT排名。
- 獲取,因為它是第一個注冊的網(wǎng)站域名年齡
- 獲取的Twitter網(wǎng)站頁面的數(shù)量
- 獲取的Facebook鏈接的網(wǎng)站頁面
- 獲取網(wǎng)站谷歌網(wǎng)頁速度等級
- 獲取網(wǎng)站的谷歌網(wǎng)頁排名

<?php
/**
 *
 * SEO report for different metrics
 *
 * @category SEO
 * @author Chema <chema@garridodiaz.com>
 * @copyright (c) 2009-2012 Open Classifieds Team
 * @license GPL v3
 * Based on seo report script http://www.phpeasycode.com && PHP class SEOstats
 *
 */
class seoreport{
  /**
   *
   * check if a url is online/alive
   * @param string $url
   * @return bool
   */
  public static function is_alive($url)
  {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HEADERFUNCTION, 'curlHeaderCallback');
    curl_setopt($ch, CURLOPT_FAILONERROR, 1);
    curl_exec ($ch);
    $int_return_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close ($ch);
    if ($int_return_code != 200 && $int_return_code != 302 && $int_return_code != 304)
    {
      return FALSE;
    }
    else return TRUE;
  }
  /**
   * HTTP GET request with curl.
   *
   * @param string $url String, containing the URL to curl.
   * @return string Returns string, containing the curl result.
   *
   */
  protected static function get_html($url)
  {
    $ch = curl_init($url);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,5);
    curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
    curl_setopt($ch,CURLOPT_MAXREDIRS,2);
    if(strtolower(parse_url($url, PHP_URL_SCHEME)) == 'https')
    {
      curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,1);
      curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,1);
    }
    $str = curl_exec($ch);
    curl_close($ch);
    return ($str)?$str:FALSE;
  }
  /**
   *
   * get the domain from any URL
   * @param string $url
   */
  public static function domain_name($url)
  {
    $nowww = ereg_replace('www\.','',$url);
    $domain = parse_url($nowww);
    if(!empty($domain["host"]))
      return $domain["host"];
    else
      return $domain["path"];
  }
  /**
   *
   * get the metas from a url and the language of the site
   * @param string $url
   * @return array
   */
  public static function meta_info($url)
  {
    //doesn't work at mediatemple
    /*$html = new DOMDocument();
    if(!$html->loadHtmlFile($url))
      return FALSE;*/
    if (!$html_content = self::get_html($url))
        return FALSE;
    $html = new DOMDocument();
    $html->loadHtml($html_content);
       
    $xpath = new DOMXPath( $html );
    $url_info = array();
    $langs = $xpath->query( '//html' );
    foreach ($langs as $lang)
    {
      $url_info['language'] = $lang->getAttribute('lang');
    }
    $metas = $xpath->query( '//meta' );
    foreach ($metas as $meta)
    {
      if ($meta->getAttribute('name'))
      {
        $url_info[$meta->getAttribute('name')] = $meta->getAttribute('content');
      }
    }
    return $url_info;
  }
  /**
   *
   * Alexa rank
   * @param string $url
   * @return integer
   */
  public static function alexa_rank($url)
  {
    $domain   = self::domain_name($url);
    $request   = "http://data.alexa.com/data?cli=10&amp;dat=s&amp;url=" . $domain;
    $data     = self::get_html($request);
    preg_match('/<POPULARITY URL="(.*?)" TEXT="([\d]+)"\/>/si', $data, $p);
    return ($l[2]) ? $l[2] : NULL;
  }
  /**
   *
   * Alexa inbounds link
   * @param string $url
   * @return integer
   */
  public static function alexa_links($url)
  {
    $domain   = self::domain_name($url);
    $request   = "http://data.alexa.com/data?cli=10&amp;dat=s&amp;url=" . $domain;
    $data     = self::get_html($request);
    preg_match('/<LINKSIN NUM="([\d]+)"\/>/si', $data, $l);
    return ($l[1]) ? $l[1] : NULL;
  }
  /**
   * Returns total amount of results for any Google search,
   * requesting the deprecated Websearch API.
   *
   * @param    string    $query   String, containing the search query.
   * @return    integer          Returns a total count.
   */
  public static function google_pages($url)
  {
    //$query = self::domain_name($url);
    $url = 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&rsz=1&q='.$url;
    $str = self::get_html($url);
    $data = json_decode($str);
    return (!isset($data->responseData->cursor->estimatedResultCount))
        ? '0'
        : intval($data->responseData->cursor->estimatedResultCount);
  }
  /**
   *
   * gets the inbounds links from a site
   * @param string $url
   * @param integer
   */
  public static function google_links($url)
  {
    $request   = "http://www.google.com/search?q=" . urlencode("link:" . $url) . "&amp;hl=en";
    $data     = self::get_html($request);
    preg_match('/<div id=resultStats>(About )?([\d,]+) result/si', $data, $l);
    return ($l[2]) ? $l[2] : NULL;
  }
  /**
   *
   * web of trust rating
   * @param string $url
   * @reutn integer
   */
  public static function WOT_rating($url)
  {
    $domain = self::domain_name($url);
    $request = "http://api.mywot.com/0.4/public_query2?target=" . $domain;
    $data   = self::get_html($request);
    preg_match_all('/<application name="(\d+)" r="(\d+)" c="(\d+)"\/>/si', $data, $regs);
    $trustworthiness = ($regs[2][0]) ? $regs[2][0] : NULL;
    return (is_numeric($trustworthiness))? $trustworthiness:NULL;
  }
   
  /**
   *
   * how old is the domain?
   * @param string $domain
   * @return integer unixtime
   */
  public static function domain_age($domain)
  {
    $request = "http://reports.internic.net/cgi/whois?whois_nic=" . $domain . "&type=domain";
    $data   = self::get_html($request);
    preg_match('/Creation Date: ([a-z0-9-]+)/si', $data, $p);
    return (!$p[1])?FALSE:strtotime($p[1]);
  }
  /**
   *
   * counts how many tweets about the url
   * @param string $url
   * @return integer
   */
  public static function tweet_count($url)
  {
    $url = urlencode($url);
    $twitterEndpoint = "http://urls.api.twitter.com/1/urls/count.json?url=%s";
    $fileData = file_get_contents(sprintf($twitterEndpoint, $url));
    $json = json_decode($fileData, true);
    unset($fileData);        // free memory
    return (is_numeric($json['count']))? $json['count']:NULL;
  }
  /**
   * Returns the total amount of Facebook Shares for a single page
   *
   * @link     https://graph.facebook.com/
   * @param     string   The URL to check.
   * @return    integer  Returns the total amount of Facebook
   */
  public static function facebook_shares($q)
  {
    //Execution and result of Json
    $str = self::get_html('http://graph.facebook.com/?id='.urlencode($q));
    $data = json_decode($str);
    //Return only number of facebook shares
    $r = $data->shares;
    return ($r != NULL) ? $r : intval('0');
  }
  /**
   *
   * get the pagespeed rank over 100
   * @param string $url
   * @return integer
   */
  public static function page_speed($url)
  {
    $url = 'https://developers.google.com/_apps/pagespeed/run_pagespeed?url='.$url.'&format=json';
    $str = self::get_html($url);
    $data = json_decode($str);
    return intval($data->results->score);
  }
  /**
   *
   * get google page rank
   * @param string $url
   * @return integer
   */
  public static function page_rank($url)
  {
     $query = "http://toolbarqueries.google.com/tbr?client=navclient-auto&ch=".self::CheckHash(self::HashURL($url)). "&features=Rank&q=info:".$url."&num=100&filter=0";
      $data = self::get_html($query);//die(print_r($data));
    $pos  = strpos($data, "Rank_");
    if($pos === false)
    {
      return NULL;
    }
    else
    {
      $pagerank = substr($data, $pos + 9);
      return $pagerank;
    }
  }
  // functions for google pagerank
  /**
   * To calculate PR functions
   */
  public static function StrToNum($Str, $Check, $Magic)
  {
    $Int32Unit = 4294967296; // 2^32
    $length = strlen($Str);
    for ($i = 0; $i < $length; $i++) {
      $Check *= $Magic;
      //If the float is beyond the boundaries of integer (usually +/- 2.15e+9 = 2^31),
      // the result of converting to integer is undefined
      // refer to http://www.php.net/manual/en/language.types.integer.php
      if ($Check >= $Int32Unit) {
        $Check = ($Check - $Int32Unit * (int) ($Check / $Int32Unit));
        //if the check less than -2^31
        $Check = ($Check < -2147483648) ? ($Check + $Int32Unit) : $Check;
      }
      $Check += ord($Str{$i});
    }
    return $Check;
  }
  /**
   * Genearate a hash for a url
   */
  public static function HashURL($String)
  {
    $Check1 = self::StrToNum($String, 0x1505, 0x21);
    $Check2 = self::StrToNum($String, 0, 0x1003F);
    $Check1 >>= 2;
    $Check1 = (($Check1 >> 4) & 0x3FFFFC0 ) | ($Check1 & 0x3F);
    $Check1 = (($Check1 >> 4) & 0x3FFC00 ) | ($Check1 & 0x3FF);
    $Check1 = (($Check1 >> 4) & 0x3C000 ) | ($Check1 & 0x3FFF);
    $T1 = (((($Check1 & 0x3C0) << 4) | ($Check1 & 0x3C)) <<2 ) | ($Check2 & 0xF0F );
    $T2 = (((($Check1 & 0xFFFFC000) << 4) | ($Check1 & 0x3C00)) << 0xA) | ($Check2 & 0xF0F0000 );
    return ($T1 | $T2);
  }
  /**
   * genearate a checksum for the hash string
   */
  public static function CheckHash($Hashnum)
  {
    $CheckByte = 0;
    $Flag = 0;
    $HashStr = sprintf('%u', $Hashnum) ;
    $length = strlen($HashStr);
    for ($i = $length - 1; $i >= 0; $i --) {
      $Re = $HashStr{$i};
      if (1 === ($Flag % 2)) {
        $Re += $Re;
        $Re = (int)($Re / 10) + ($Re % 10);
      }
      $CheckByte += $Re;
      $Flag ++;
    }
    $CheckByte %= 10;
    if (0 !== $CheckByte) {
      $CheckByte = 10 - $CheckByte;
      if (1 === ($Flag % 2) ) {
        if (1 === ($CheckByte % 2)) {
          $CheckByte += 9;
        }
        $CheckByte >>= 1;
      }
    }
    return '7'.$CheckByte.$HashStr;
  }
}

使用范例

<?php
include 'seoreport.php';
ini_set('max_execution_time', 180);
  $url = (isset($_GET['url']))?$_GET['url']:'http://phpclasses.org';
  $meta_tags = seoreport::meta_info($url);
  //die(var_dump($meta_tags));
  //first check if site online
  if ($meta_tags!==FALSE)
  {
    $stats = array();
    $stats['meta'] = $meta_tags;
    $stats['alexa']['rank'] = seoreport::alexa_rank($url);
    $stats['alexa']['links'] = seoreport::alexa_links($url);
    $stats['domain']['WOT_rating'] = seoreport::WOT_rating($url);  
    $stats['domain']['domain_age'] = seoreport::domain_age($url);  
    $stats['social']['twitter'] = seoreport::tweet_count($url);  
    $stats['social']['facebook'] = seoreport::facebook_shares($url);
    $stats['google']['page_rank'] = seoreport::page_rank($url);
    $stats['google']['page_speed'] = seoreport::page_speed($url);
    $stats['google']['pages'] = seoreport::google_pages($url);
    $stats['google']['links'] = seoreport::google_links($url);
    var_dump($stats);
  }
  else 'Site not online. '.$url;

希望本文所述對大家的php程序設(shè)計有所幫助。

相關(guān)文章

  • PHP中調(diào)試函數(shù)debug_backtrace的使用示例代碼

    PHP中調(diào)試函數(shù)debug_backtrace的使用示例代碼

    debug_backtrace() 是一個很低調(diào)的函數(shù),很少有人注意過它,這篇文章主要給大家介紹了關(guān)于PHP中調(diào)試函數(shù)debug_backtrace的使用方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,感興趣的朋友們隨著小編來一起學習學習吧。
    2017-09-09
  • PHP實現(xiàn)簡單鑒權(quán)的示例代碼

    PHP實現(xiàn)簡單鑒權(quán)的示例代碼

    這篇文章主要為大家詳細介紹了php如何通過在header增加key,sign,timestamp來實現(xiàn)鑒權(quán),文中的示例代碼講解詳細,需要的小伙伴可以參考下
    2023-12-12
  • PHP中的traits實現(xiàn)代碼復用使用實例

    PHP中的traits實現(xiàn)代碼復用使用實例

    這篇文章主要介紹了PHP中的traits實現(xiàn)代碼復用使用實例,本文講解了Trait簡單使用、優(yōu)先級問題、多個Trait沖突問題、as可用來修改方法訪問控制、Trait中使用Trait等內(nèi)容,需要的朋友可以參考下
    2015-05-05
  • php使用ereg驗證文件上傳的方法

    php使用ereg驗證文件上傳的方法

    這篇文章主要介紹了php使用ereg驗證文件上傳的方法,是非常簡單實用的正則驗證技巧,具有一定的參考借鑒價值,需要的朋友可以參考下
    2014-12-12
  • php錯誤提示failed to open stream: HTTP request failed!的完美解決方法

    php錯誤提示failed to open stream: HTTP request failed!的完美解決方法

    當使用php5自帶的file_get_contents方法來獲取遠程文件的時候,有時候會出現(xiàn)file_get_contents(): failed to open stream: HTTP request failed!這個警告信息。
    2011-06-06
  • php-fpm報502問題的解決辦法

    php-fpm報502問題的解決辦法

    這篇文章主要介紹了php-fpm報502問題的解決辦法,遇到此類問題的同學,可以參考下
    2021-04-04
  • php文件上傳簡單實現(xiàn)方法

    php文件上傳簡單實現(xiàn)方法

    這篇文章主要介紹了php文件上傳簡單實現(xiàn)方法,以一個完整實例形式分析了文件上傳的過程,具有一定參考借鑒價值,需要的朋友可以參考下
    2015-01-01
  • PHP實現(xiàn)RabbitMQ消息列隊的示例代碼

    PHP實現(xiàn)RabbitMQ消息列隊的示例代碼

    眾所周知,php本身的運行效率存在一定的缺陷,所以如果有一個很復雜很耗時的業(yè)務時,必須開發(fā)一個常駐內(nèi)存的程序。本文將利用PHP實現(xiàn)RabbitMQ消息列隊,感興趣的可以了解一下
    2022-05-05
  • php sprintf()函數(shù)讓你的sql操作更安全

    php sprintf()函數(shù)讓你的sql操作更安全

    本函數(shù)用來將字符串格式化。參數(shù) format 是轉(zhuǎn)換的格式,以百分比符號 % 開始到轉(zhuǎn)換字符為止。而在轉(zhuǎn)換的格式間依序包括了
    2008-07-07
  • php使用fsockopen函數(shù)發(fā)送post,get請求獲取網(wǎng)頁內(nèi)容的方法

    php使用fsockopen函數(shù)發(fā)送post,get請求獲取網(wǎng)頁內(nèi)容的方法

    這篇文章主要介紹了php使用fsockopen函數(shù)發(fā)送post,get請求獲取網(wǎng)頁內(nèi)容的方法,是PHP關(guān)于socket編程的一個典型應用,需要的朋友可以參考下
    2014-11-11

最新評論

大竹县| 同江市| 永昌县| 江阴市| 宣城市| 延边| 唐山市| 扬中市| 高尔夫| 阳江市| 汨罗市| 罗山县| 上饶市| 仙居县| 邢台县| 永修县| 元阳县| 浦县| 隆昌县| 富阳市| 荣成市| 东方市| 德令哈市| 根河市| 辉县市| 湟源县| 酉阳| 淄博市| 石台县| 巴彦淖尔市| 齐齐哈尔市| 高安市| 泽州县| 元谋县| 汝南县| 阳朔县| 台山市| 图们市| 海晏县| 栾川县| 南投市|