php 获取alexa排名

<?php
	/**
	 * Get Alexa Rank
	 *
	 * @param Domain Name $Domain
	 * @return Alexa Rank 
	 * @copyright SanyWork http://www.sanywork.cn/
	 */
	function  getAlexaRank ($Domain){
		$line  = "";
		$data  = "";
		$URL  = "http://data.alexa.com/data/?cli=10&dat=snba&ver=7.0&url=". $Domain ;
		$fp  = fopen ($URL ,"r");
		if ($fp ){
			while (!feof ($fp )){
				$line  = fgets ($fp );
				$data  .= $line ; 
			}
			$p= xml_parser_create ();
			xml_parse_into_struct ($p , $data , $vals );
			xml_parser_free ($p );
			for ($i =0 ;$i <count ($vals );$i ++){
				if ($vals [$i ]["tag"]=="POPULARITY"){
					return  $vals [$i ]["attributes"]["TEXT"];    
				}
			}
		}
	}
?>


posted @ 2012-02-03 08:25  野三坡  阅读(125)  评论(0编辑  收藏  举报