开发者

beginner attempting to read xml into php

I have an xml feed located here that I am trying to read into a php script, then cycle through the <packages>, and sum the <downloads>. I've attempted to do this using DOMDocument, but have thus far failed.

the basic method i've been trying to use is as follows

<?php
$dom = new DomDocument;
$dom->loadXML('http://www.phogue.net/feed');
$packages = $dom->getElementsByTagName('package');
foreach($packages as $item)
{
    echo $item->getAttribute('uid').'<br>';
}
?>

The above code is meant to just print out the name of each item, but its not working. I am currently getting the following error

Warning: DOMDocument::loadXML() [domdocument.loadxml]: Start tag expected, '<' not found in Entity, line: 1 in /home/a8744502/public_html/userbar.php on line 3

WORKING CODE:

<?php
$dom = new DomDocument;
$dom-&g开发者_开发技巧t;load('http://www.phogue.net/feed/');
$package = $dom->getElementsByTagName('package');
$value=0;

foreach ($package as $plugin) {

    $downloads = $plugin->getElementsByTagName("downloads");
    $download = $downloads->item(0)->nodeValue;

    $authors = $plugin->getElementsByTagName("author");
    $author = $authors->item(0)->nodeValue;
    if($author == "Zaeed")
    {
        $value += $download;
    }
}
echo $value;
?>


DOMDocument::loadXML() expects a string of XML. Try DOMDocument::load() instead - http://www.php.net/manual/en/domdocument.load.php

Keep in mind that to open an XML file via HTTP, you will need the appropriate wrapper enabled.


You have a open parenthesis at the beginning of your echo.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜