65.9K
CodeProject is changing. Read more.
Home

Alexa ranking using php script

starIconstarIconstarIconemptyStarIconemptyStarIcon

3.00/5 (1 vote)

Nov 15, 2010

CPOL
viewsIcon

19868

if you want to check the your website ranking as per alexa so you can use the following code in your php projects. http://data.alexa.com/data?cli=10&dat=s&url=how2dev.com “http://data.alexa.com/data” this file will return the xml format output. Using the XML output or reading xml file we can easily fetch the our or any website ranking. Use the following function for getting the alexa website ranking.
function AlexaRank( $url )
{
preg_match( '#<POPULARITY URL="(.*?)" TEXT="([0-9]+){1,}"/>#si', file_get_contents('http://data.alexa.com/data?cli=10&dat=s&url=' . $url), $p );
return ( $p[2] ) ? number_format( intval($p[2]) ):0;
}
echo "wordpressapi.com Rank as per alexa.com: ";
echo AlexaRank('how2dev.com');
?>
if you want to check the multiple website ranking in one shot than use the following PHP code.
$domains = array( 'google.com', 'ask.com', 'yahoo.com', 'bing.com' );

foreach ( $domains as $domain )
echo $domain, ' - ', AlexaRank( $domain ), '
', PHP_EOL; ?>