如何在我现有的单个文件脚本中添加一个xml文件数组


How to add an array of xml files in my existing single file script?

下面的代码获取文件的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;
}
?>
$sum = $sum.$contents

这样可以吗?

尝试使用:

$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);
    }
}