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

时间:2011-07-04 03:20:22

标签: php dom

以下代码获取文件的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;

}

?>

2 个答案:

答案 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);
    }

}