⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 alexa.php

📁 PHP获取网站的alexa世界排名等
💻 PHP
字号:
<?
 //By Code52.net
 //更多代码教程,尽在『代码吾爱』。
 //Be a happy coder

/* the alexa rank class */  
class alexaRank   
{   
    /* 初始化 */  
    var $xml;   
    var $values;   
    var $alexa_address;   
  
    /* PHP5构造函数*/  
    function alexa($alexa_address,$domain)   
    {   
        $this->alexa_address = $alexa_address;   
        $this->xml = $this->get_data($domain);   
        $this->set();   
    }   
  
    /* 远程获取Alexa提供的XML文件 */  
    function get_data($domain)   
    {   
        $url = $this->alexa_address.'http://'.$domain;   
        $xml = simplexml_load_file($url) or die('解析远程XML失败');   
        return $xml;   
    }   
  
    /* 设置我们想要的值 */  
    function set()   
    {   
        $this->values['rank'] = ($this->xml->SD->POPULARITY['TEXT'] ? number_format($this->xml->SD->POPULARITY['TEXT']) : 0);   
        $this->values['reach'] = ($this->xml->SD->REACH['RANK'] ? number_format($this->xml->SD->REACH['RANK']) : 0);   
        $this->values['linksin'] = ($this->xml->SD->LINKSIN['NUM'] ? number_format($this->xml->SD->LINKSIN['NUM']) : 0);   
    }   
  
    /* 返回函数 */  
    function get($value)   
    {   
        return (isset($this->values[$value]) ? $this->values[$value] : '"'.$value.'" 不存在.');   
    }   
}  

 /*显示 */  
$alexa_connector = new alexaRank('http://alexa.com/xml/dad?url=',$domain); 
echo '综合排名: '.$alexa_connector->get('rank').'<br />'; 
echo '';   
echo '每百万人浏览人数:'.$alexa_connector->get('reach').'<br />'; 
echo '';   
echo '反向链接:'.$alexa_connector->get('linksin');
?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -