侯体宗的博客
  • 首页
  • 人生(杂谈)
  • 技术
  • 关于我
  • 更多分类
    • 文件下载
    • 文字修仙
    • 中国象棋ai
    • 群聊
    • 九宫格抽奖
    • 拼图
    • 消消乐
    • 相册

php实现专业获取网站SEO信息类实例

php  /  管理员 发布于 7年前   182

本文实例讲述了php实现专业获取网站SEO信息类。分享给大家供大家参考。具体如下:

这个seo类的功能包括:
- 检查指定的网站响应
- 获取从该网站主页的语言和其他meta标签数据的
- 获取网站的导入链接,从Alexa的流量排名
- 获取网站的导入链接,由谷歌索引的网页数量
- 获取网站的信任,从WOT排名。
- 获取,因为它是第一个注册的网站域名年龄
- 获取的Twitter网站页面的数量
- 获取的Facebook链接的网站页面
- 获取网站谷歌网页速度等级
- 获取网站的谷歌网页排名

 * @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&dat=s&url=" . $domain;    $data     = self::get_html($request);    preg_match('//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&dat=s&url=" . $domain;    $data     = self::get_html($request);    preg_match('//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) . "&hl=en";    $data     = self::get_html($request);    preg_match('/
(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('//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程序设计有所帮助。

您可能感兴趣的文章:

  • GREATNUKE为您提供免费PHP-Nuke建站系统
  • 建站常用13种PHP开源CMS比较
  • 国外比较好的几个的Php开源建站平台小结
  • php判断终端是手机还是电脑访问网站的思路及代码
  • PHP怎么实现网站保存快捷方式方便用户随时浏览
  • 使用PHP curl模拟浏览器抓取网站信息
  • php获取从百度搜索进入网站的关键词的详细代码
  • php网站地图生成类示例
  • 使用php记录用户通过搜索引擎进网站的关键词
  • 推荐10个提供免费PHP脚本下载的网站
  • PHP+jquery实时显示网站在线人数的方法
  • php使用cookie显示用户上次访问网站日期的方法
  • PHP网站开发中常用的8个小技巧
  • php实现统计网站在线人数的方法
  • php中smarty实现多模版网站的方法
  • PHP网站建设的流程与步骤分享


  • 上一条:
    php实现在限定区域里自动调整字体大小的类实例
    下一条:
    php获得网站访问统计信息类Compete API用法实例
  • 昵称:

    邮箱:

    0条评论 (评论内容有缓存机制,请悉知!)
    最新最热
    • 分类目录
    • 人生(杂谈)
    • 技术
    • linux
    • Java
    • php
    • 框架(架构)
    • 前端
    • ThinkPHP
    • 数据库
    • 微信(小程序)
    • Laravel
    • Redis
    • Docker
    • Go
    • swoole
    • Windows
    • Python
    • 苹果(mac/ios)
    • 相关文章
    • Laravel从Accel获得5700万美元A轮融资(0个评论)
    • PHP 8.4 Alpha 1现已发布!(0个评论)
    • 用Time Warden监控PHP中的代码处理时间(0个评论)
    • 在PHP中使用array_pop + yield实现读取超大型目录功能示例(0个评论)
    • Property Hooks RFC在PHP 8.4中越来越接近现实(0个评论)
    • 近期文章
    • 在windows10中升级go版本至1.24后LiteIDE的Ctrl+左击无法跳转问题解决方案(0个评论)
    • 智能合约Solidity学习CryptoZombie第四课:僵尸作战系统(0个评论)
    • 智能合约Solidity学习CryptoZombie第三课:组建僵尸军队(高级Solidity理论)(0个评论)
    • 智能合约Solidity学习CryptoZombie第二课:让你的僵尸猎食(0个评论)
    • 智能合约Solidity学习CryptoZombie第一课:生成一只你的僵尸(0个评论)
    • 在go中实现一个常用的先进先出的缓存淘汰算法示例代码(0个评论)
    • 在go+gin中使用"github.com/skip2/go-qrcode"实现url转二维码功能(0个评论)
    • 在go语言中使用api.geonames.org接口实现根据国际邮政编码获取地址信息功能(1个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf分页文件功能(95个评论)
    • gmail发邮件报错:534 5.7.9 Application-specific password required...解决方案(0个评论)
    • 近期评论
    • 122 在

      学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..
    • 123 在

      Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..
    • 原梓番博客 在

      在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..
    • 博主 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..
    • 1111 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
    • 2016-10
    • 2016-11
    • 2017-06
    • 2017-07
    • 2017-08
    • 2017-09
    • 2017-11
    • 2017-12
    • 2018-01
    • 2018-02
    • 2018-03
    • 2020-03
    • 2020-04
    • 2020-05
    • 2020-06
    • 2020-07
    • 2020-09
    • 2021-02
    • 2021-03
    • 2021-04
    • 2021-05
    • 2021-06
    • 2021-07
    • 2021-08
    • 2021-09
    • 2021-10
    • 2021-11
    • 2021-12
    • 2022-01
    • 2022-02
    • 2022-05
    • 2022-06
    • 2022-07
    • 2022-08
    • 2022-09
    • 2022-10
    • 2022-11
    • 2022-12
    • 2023-01
    • 2023-02
    • 2023-03
    • 2023-04
    • 2023-05
    • 2023-06
    • 2023-07
    • 2023-08
    • 2023-09
    • 2023-10
    • 2023-11
    • 2023-12
    • 2024-01
    • 2024-02
    • 2024-03
    • 2024-04
    • 2024-05
    • 2024-06
    • 2024-07
    • 2024-09
    Top

    Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号 PHP交流群

    侯体宗的博客