How to add an array of xml files in my existing single file script?
The following code gets the fan_count of the file and shows it. What I want to do is to create an array that can hold many urls and echo each one the fan_count.
How can I modify the code ? Thank you
<?php
$dom = new DOMDocument;
$dom->loadHTMLFile ('domain.com/xmlfile.xml');
$xPath = new DOMXPa开发者_如何学编程th($dom);
$posts = $xPath->query('//page');
foreach($posts as $post) {
$fans = $post->getElementsByTagName( "fan_count" )->item(0)->nodeValue;
echo $fans;
}
?>
$sum = $sum.$contents
is this ok?
Try with:
$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);
}
}
精彩评论