以下代码获取文件的fan_count并显示它。我想要做的是创建一个可以容纳许多网址的数组,并将每个网址回显给fan_count。
如何修改代码?谢谢
<?php
$dom = new DOMDocument;
$dom->loadHTMLFile ('domain.com/xmlfile.xml');
$xPath = new DOMXPath($dom);
$posts = $xPath->query('//page');
foreach($posts as $post) {
$fans = $post->getElementsByTagName( "fan_count" )->item(0)->nodeValue;
echo $fans;
}
?>
答案 0 :(得分:0)
$sum = $sum.$contents
这样可以吗?
答案 1 :(得分:-1)
尝试:
$feeds = array(
'https://api.facebook.com/method/fql.query?query=SELECT%20fan_count%20FROM%20page%20WHERE%20page_id=1234567',
'https://api.facebook.com/method/fql.query?query=SELECT%20fan_count%20FROM%20page%20WHERE%20page_id=7564321'
);
foreach ($feeds as $feed) {
$xml = simplexml_load_file($feed);
$fans_numbers = $xml->xpath("//fan_count");
foreach ($fans_numbers as $elem){
print_r($elem);
}
}