我正在尝试从Contrie接收有关Alexa热门网站的信息,我希望收到:
对于我已经获得的URL,但是当我为网站位置添加标签时,某些东西不起作用,这是我的代码:
<?php
for ($z=0;$z<2;$z++) {
$html=file_get_contents('http://www.alexa.com/topsites/countries;'.$z.'/PT');
preg_match_all(
'/<div class="count">.*?<\/div>.*?<a href="\/siteinfo\/.*?">(.*?)<\/a>/s',
$html,
$array, //array with sites
PREG_SET_ORDER
);
for ($i=1;$i<count($array);$i++) {
echo "<pre>"; print_r($array); echo "</pre>";
}
}
?>
Run Code Online (Sandbox Code Playgroud)
我明白了:
Array
(
[0] => Array
(
[0] =>
1
google.pt
[1] => google.pt
)
[1] => Array
(
[0] =>
2
Run Code Online (Sandbox Code Playgroud)
要使用PHP获取网站的Alexa排名,您可以使用以下代码:
<?
$url="http://theurl.com";
$xml = simplexml_load_file('http://data.alexa.com/data?cli=10&dat=snbamz&url='.$url);
$rank=isset($xml->SD[1]->POPULARITY)?$xml->SD[1]->POPULARITY->attributes()->TEXT:0;
$web=(string)$xml->SD[0]->attributes()->HOST;
echo $web." has an alexa rank of: ".$rank;
?>
Run Code Online (Sandbox Code Playgroud)
希望有所帮助
来源 - http://99webtools.com/php-script-to-get-alexa-rank.php
| 归档时间: |
|
| 查看次数: |
1871 次 |
| 最近记录: |