Results 1 to 7 of 7
-
8th Feb 2012, 11:50 AM #1
OPBannedWebsite's:
Seecure.me
[PHP] GetAlexaTrafficRank
[PHP] GetAlexaTrafficRank
Pass through a domain without 'www' in "$domain". Read, Learn, Modify, Re-use.
Example output:

Code:
Code:<?php /** * This is simple description. * * @author Vick Kumar <vickkumar2011@gmail.com> * @copyright Seecure.me, 2012 * @version 1.0 * @license http://creativecommons.org/licenses/by/3.0/legalcode */ function GetAlexaTrafficRank($domain) { $source = file_get_contents("http://www.alexa.com/siteinfo/$domain#"); $regex = '/is ranked (.*) in/'; preg_match($regex, $source, $match); $newresult = str_replace("number", "", $match[1]); return $newresult; } echo "Seecure.ME's Alexa Traffic Rank is: ".GetAlexaTrafficRank("seecure.me")."."; ?>_Vick Reviewed by _Vick on . [PHP] GetAlexaTrafficRank GetAlexaTrafficRank Pass through a domain without 'www' in "$domain". Read, Learn, Modify, Re-use. Example output: http://screensnapr.com/e/uOxR3O.jpg Code: <?php Rating: 5
-
8th Feb 2012, 11:53 AM #2
MemberWebsite's:
Elite.SO Defendos.com Motionite.comFixedPHP Code:<?php
/**
* This is simple description.
*
* @author Vick Kumar <vickkumar2011@gmail.com>
* @copyright Seecure.me, 2012
* @version 1.0
* @license http://creativecommons.org/licenses/by/3.0/legalcode
*/
$domain = 'besthostingforums.com';
function GetAlexaTrafficRank($domain)
{
$source = file_get_contents("http://www.alexa.com/siteinfo/$domain#");
$regex = '/is ranked (.*) in/';
preg_match($regex, $source, $match);
$newresult = str_replace("number", "", $match[1]);
return $newresult;
}
echo $domain." 's Alexa Traffic Rank is: ".GetAlexaTrafficRank($domain).".";
?>
Easier for them noobs.
-
8th Feb 2012, 12:01 PM #3
OPBannedWebsite's:
Seecure.me^ Won't work due to $domain is passed via function, not set outside of function etc.
-
8th Feb 2012, 12:04 PM #4
MemberWebsite's:
Elite.SO Defendos.com Motionite.comYeah, but it will work if you have the $domain variable in your code.
Goodjob btw
-
8th Feb 2012, 12:06 PM #5
MemberThis should strip "http://", "https://", "www.", so you can pass almost any domain to the function.PHP Code:function GetAlexaTrafficRank($domain) {
$domain = preg_replace('#(https?://)?(www\.)?#i','',$domain);
...
-
8th Feb 2012, 01:05 PM #6
Respected Member
Website's:
DL4Everything.com Soft2050.inThe Regex failed

Try it yourself and heres the result:PHP Code:<?php
/**
* This is simple description.
*
* @author Vick Kumar <vickkumar2011@gmail.com>
* @copyright Seecure.me, 2012
* @version 1.0
* @license http://creativecommons.org/licenses/by/3.0/legalcode
*/
function GetAlexaTrafficRank($domain)
{
$source = file_get_contents("http://www.alexa.com/siteinfo/$domain#");
$regex = '/is ranked (.*) in/';
preg_match($regex, $source, $match);
$newresult = str_replace("number", "", $match[1]);
return $newresult;
}
echo "KWWHunction's Alexa Traffic Rank is: ".GetAlexaTrafficRank("besthostingforums.com").".";
?>

Fix the regex
-
8th Feb 2012, 06:45 PM #7
Memberhttp://www.alexa.com/siteinfo/besthostingforums.com
That's why the regex fails.The rank is calculated using a combination of average daily visitors to
besthostingforums.com and pageviews on besthostingforums.com over the past 3 months. The site with the highest combination of visitors and pageviews is ranked #1.
Here's a fix:
PHP Code:function GetAlexaTrafficRank($domain)
{
$source = file_get_contents("http://www.alexa.com/siteinfo/$domain#");
$regex = '#([0-9,]+)\s*</div>\s*<div class="label">Global Rank#';
preg_match($regex, $source, $match);
$newresult = str_replace("number", "", $match[1]);
return $newresult;
}
echo "KWWHunction's Alexa Traffic Rank is: ".GetAlexaTrafficRank("besthostingforums.com").".";
Sponsored Links
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)








Register To Reply


Staff Online
themaCreator - create posts from...
Version 3.55 released. Open older version (or...