Tag Archive for CODE

what is the php code to get real alexa rank for a given website in textbox?

Question by Bhupender Saharan: what is the php code to get real alexa rank for a given website in textbox?
what is the php code to get real alexa rank for a given website in textbox?

Best answer:

Answer by Leonardo M
Alexa does not offer any free API to obtain Alexa Rank. However there is a simple method to obtain it in the same way the Alexa Toolbar does. All you have to do is to invoke the following url(replacing php-html.net with your domain): http://data.alexa.com/data?cli=10&dat=s&url=php-html.net

Then you have to build your php code to catch the rank within the response from the above url. Try to use the function below in order to return the Alexa rank:

function alexaRank($ domain){
$ remote_url = ‘http://data.alexa.com/data?cli=10&dat=snbamz&url=’.trim($ domain);
$ search_for = ‘ if ($ handle = @fopen($ remote_url, "r")) {
while (!feof($ handle)) {
$ part .= fread($ handle, 100);
$ pos = strpos($ part, $ search_for);
if ($ pos === false)
continue;
else
break;
}
$ part .= fread($ handle, 100);
fclose($ handle);
}
$ str = explode($ search_for, $ part);
$ str = array_shift(explode('"/>‘, $ str[1]));
$ str = explode(‘TEXT=”‘, $ str);

return $ str[1];
}

If it does not work, at least it may be a good start point. Therefore, try to modify the code based on the response from the above url until it works.

Add your own answer in the comments!

Shared on Ariyan.org