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

时间:2021-05-26

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

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

<?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:///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; }}

使用范例

<?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::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程序设计有所帮助。

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章