php – 如何从alexa API获取竞争对手记录到数组

前端之家收集整理的这篇文章主要介绍了php – 如何从alexa API获取竞争对手记录到数组前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我打电话给 http://data.alexa.com/data?cli=10&dat=snbamz&url=www.flipkart.com获取网站数据,当我在浏览器上运行它显示这个XML.
<ALEXA VER="0.9" URL="flipkart.com/" HOME="0" AID="=" IDN="flipkart.com/">
<RLS PREFIX="http://" more="0">
<RL HREF="storewala.com/" TITLE="Storewala.com - Indian Retail Store"/>
<RL HREF="pdf-search-engine.com/" TITLE="Ebook Search - Pdf Search Engine"/>
<RL HREF="overnitenet.com/" TITLE="-----Overnite-----"/>
<RL HREF="nbcindia.com/" TITLE="Online Book Stores,India's Largest Bookstore,Nbc India.com"/>
<RL HREF="mouthshut.com/" TITLE="Mouthshut.com - Consumer Reviews Helping You Decide"/>
<RL HREF="landmarkonthenet.com/" TITLE="Land Mark"/>
<RL HREF="ingrambook.com/" TITLE="Ingram Book Group"/>
<RL HREF="infibeam.com/" TITLE="InfiBeam - Gifts to India | Online Shopping India | Books,Cameras,Watches,Mob"/>
<RL HREF="indiaplaza.in/" TITLE="Fabmall House"/>
<RL HREF="firstflight.net/" TITLE="FirstFlight Courier"/>
</RLS>
<SD TITLE="A" FLAGS="" HOST="flipkart.com">
<TITLE TEXT="Flipkart.com"/>
<OWNER NAME="Flipkart.com"/>
</SD>
<SD>
<POPULARITY URL="flipkart.com/" TEXT="116" SOURCE="panel"/>
<REACH RANK="130"/>
<RANK DELTA="+5"/>
<COUNTRY CODE="IN" NAME="India" RANK="8"/>
</SD>
</ALEXA>

我正在取得人气和国家排名.

$xml = simplexml_load_file('http://data.alexa.com/data?cli=10&dat=snbamz&url=www.flipkart.com');
$rank=isset($xml->SD[1]->POPULARITY)?$xml->SD[1]->POPULARITY->attributes()->TEXT:0;
$country_rank=isset($xml->SD[1]->COUNTRY)?$xml->SD[1]->COUNTRY->attributes()->RANK:0;

它的工作正常,但我不知道如何获取所有RL标签HREF属性在数组中.

我希望它能帮助你.
$xml = simplexml_load_file('http://data.alexa.com/data?cli=10&dat=snbamz&url=www.flipkart.com');

foreach($xml->RLS->children() as $key => $val){

    $href = (string)($val->attributes()->HREF);
    $title= (string)($val->attributes()->TITLE);

    echo 'HREF : ' .  $href . ' TITLE: ' . $title . '<br />';
}
原文链接:https://www.f2er.com/php/139619.html

猜你在找的PHP相关文章