www.statbrain.com

www.statbrain.com

StatBrain.com is one of interesting site which has been popular recently with it’s free service to calculate visitor stats of any website. Although any sites on the web can’t provide exact visitor stats without accessing the website logs, I personally like the calculation of StatBrain.com which seems to be close for most of the websites. StatBrain.com use different technologies and calculation methods for showing the visitors stats.

In their own words “It is incredible what a bit of research on the Internet can do. Actually I’m pretty good at it. I usually say: ‘If its out there I can find it’ and most of the time it is true. I’m also a very curious person, some might say a bit too curious. When I see a new site I have to know one thing; how many daily visits does it have? Unfortunately nobody wants to tell you how many visits a site has. So you have to guess and that is kind of difficult. So I built Statbrain.com to help me and everybody else guess.”

At this time you may be thinking to use similar techniques on your own website or perhaps want to re-use the data from StatBrain.com on your website to serve your visitors. So below I have provided a PHP Tutorial on how to get data from StatBrain.com and re-use it on your website.

First of all we create a function that will extract a data from StatBrain.com

function getStatBrainVisit($value) {
	$var=file_get_contents("http://www.statbrain.com/".$value);
 
	$find1="Estimated number of visits for";
	$pos1 = strpos($var, $find1);
 
	$find2="visits per day";
	$pos2 = strpos($var, $find2);
 
	$coundDiff=$pos2-$pos1;
 
	$rawData1=strip_tags(substr($var, $pos1, $coundDiff));
 
	$rawData2=str_replace("Estimated number of visits for", "", $rawData1);
	$rawData3=str_replace("Less than", "", $rawData2);
	$finalData=str_replace($value, "", $rawData3);
 
	return trim($finalData);
}

The above function will first extract the raw data from StatBrain.com as you get while visiting the stat page by using following code:

$var=file_get_contents("http://www.statbrain.com/".$value);

The data we require from StatBrain.com is located between “Estimated number of visits for” and “visits per day”, so we first locate the position of both phrases and keep the require data with the two phrases.

$find1="Estimated number of visits for";
$pos1 = strpos($var, $find1);
 
$find2="visits per day";
$pos2 = strpos($var, $find2);
 
$coundDiff=$pos2-$pos1;
 
$rawData1=strip_tags(substr($var, $pos1, $coundDiff));

Our next process is cleaning up the data we hold till now and finally getting the numeric value, which we made via this additional code:

$rawData2=str_replace("Estimated number of visits for", "", $rawData1);
$rawData3=str_replace("Less than", "", $rawData2);
$finalData=str_replace($value, "", $rawData3);

The variable $finalData now holds the Estimated Visitors Data of any website that we want to look after. We now return the output of the variable $finalData inside the function. I have used trim() to remove any whitespaces that may be included along with final data.

return trim($finalData);

So our re-usable function for getting Estimated Visitors Data from StatBrain.com is complete. We can now use the function we just created by providing the domain name for which we want to have Estimated Visitors Data as following:

print getStatBrainVisit("www.facebook.com");

ALL CODES AT ONCE

function getStatBrainVisit($value) {
	$var=file_get_contents("http://www.statbrain.com/".$value);
 
	$find1="Estimated number of visits for";
	$pos1 = strpos($var, $find1);
 
	$find2="visits per day";
	$pos2 = strpos($var, $find2);
 
	$coundDiff=$pos2-$pos1;
 
	$rawData1=strip_tags(substr($var, $pos1, $coundDiff));
 
	$rawData2=str_replace("Estimated number of visits for", "", $rawData1);
	$rawData3=str_replace("Less than", "", $rawData2);
	$finalData=str_replace($value, "", $rawData3);
 
	return trim($finalData);
}
print getStatBrainVisit("www.facebook.com");

Hope you enjoyed this tutorial.

Similar Posts: