xml - rss parsing DOMDocument in PHP -
i'm trying categories , push them array
, far i'm doing way:
$doc = new domdocument(); $doc->load('myxml.xml'); $arr = array(); foreach ($doc->getelementsbytagname('item') $node) { $items = array ( 'title' => $node->getelementsbytagname('title')->item(0)->nodevalue, 'date' => $node->getelementsbytagname('category')->item(0)->nodevalue ); $arr [] = $items ; }
this works if have 1 cat, however, xml
has several categories per item. way of doing this?
<item> <title>submit</title> <category>foo</category> <category>bar</category> </item>
thanks
this should help:
$doc = new domdocument(); $doc->load('myxml.xml'); $arr = array(); foreach ($doc->getelementsbytagname('item') $node) { $item = array ( 'title' => $node->getelementsbytagname('title')->item(0)->nodevalue, 'date' => array() ); foreach($node->getelementsbytagname('category') $catnode) { $item['date'][] = $catnode->nodevalue; } $arr[] = $item; }
- christian
Comments
Post a Comment