PHP to achieve professional access to website SEO information class instances, SEO examples _php tutorial

Source: Internet
Author: User
Tags sprintf

PHP to achieve professional access to website SEO information class instances, SEO instances


This article describes the implementation of PHP professional access to website SEO information class. Share to everyone for your reference. Specific as follows:

The features of this SEO class include:
-Check the specified site response
-Get the language and other meta tag data from the site's home page
-Get the site's import link from Alexa traffic rankings
-Get the website's import link, the number of pages indexed by Google
-Get the site's trust from WOT rankings.
-GET, because it is the first registered website domain name age
-Get the number of Twitter site pages
-Get the Facebook link to the site page
-Get website Speed level on Google page
-Get the site's Google page rankings

<?php/** * * SEO report for different metrics * * @category seo * @author chema
 
  
 * @copyright (c) 2009-2012 Open Classifieds Team * @license GPL v3 * Based on the SEO report script http://www.phpeasycode.c   Om && 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! = && $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) {$no    www = 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 (' NA      Me ')] = $meta->getattribute (' content ');  }} return $url _info; }/** * Alexa rank * @param string $url * @return integer */public static function Alexa_rank ($url) {$    Domain = self::d omain_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 ($ur    L) {$domain = self::d omain_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::d omain_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::d omain_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 are the domain? * @param string $domain * @return Integer unixtime */public static function Domain_age ($domain) {$request = "ht Tp://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) {//execut    Ion 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 $ * @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, $Che    CK, $Magic) {$Int 32Unit = 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 Integ  ER is undefined//refer to http://www.php.net/manual/en/language.types.integer.php if ($Check >= $Int 32Unit)        {$Check = ($Check-$Int 32Unit * (int) ($Check/$Int 32Unit)); If the check less than-2^31 $Check = ($Check <-2147483648)?      ($Check + $Int 32Unit): $Check;    } $Check + = Ord ($Str {$i});  } return $Check; }/** * Genearate a hash for a URL */public static function Hashurl ($String) {$Check 1 = self::strtonum ($String    , 0x1505, 0x21);    $Check 2 = self::strtonum ($String, 0, 0x1003f);    $Check 1 >>= 2; $Check 1 = (($Check 1 >> 4) & 0x3ffffc0) |    ($Check 1 & 0x3F); $Check 1 = (($Check 1 >> 4) & 0x3ffc00) |    ($Check 1 & 0x3ff); $Check 1 = (($Check 1 >> 4) & 0x3c000) |    ($Check 1 & 0x3fff); $T 1= ((((($Check 1 & 0x3c0) << 4) | ($Check 1 & 0x3C)) &LT;&LT;2) |    ($Check 2 & 0xf0f); $T 2 = ((($Check 1 & 0xffffc000) << 4) | ($Check 1 & 0x3c00)) << 0xA) |    ($Check 2 & 0xf0f0000);  Return ($T 1 | $T 2);     }/** * 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; }}
 

Use example

<?phpinclude ' 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::d omain_age ($url);      $stats [' Social '] [' Twitter '] = Seoreport::tweet_count ($url);    $stats [' Social '] [' Facebook '] = Seoreport::facebook_shares ($url);    $stats [' Google '] [' page_rank '] = Seoreport::p age_rank ($url);    $stats [' Google '] [' page_speed '] = Seoreport::p age_speed ($url);    $stats [' Google '] [' pages '] = seoreport::google_pages ($url);    $stats [' Google '] [' links '] = Seoreport::google_links ($url);  Var_dump ($stats); } else ' Site not OnliNe. '. $url; 

I hope this article is helpful to everyone's PHP programming.

http://www.bkjia.com/PHPjc/978379.html www.bkjia.com true http://www.bkjia.com/PHPjc/978379.html techarticle PHP to achieve professional access to website SEO information class instances, SEO examples of this article about PHP to achieve professional access to website SEO information class. Share to everyone for your reference. Specific as follows: This SEO class ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.