Skip to content

Instantly share code, notes, and snippets.

@mach3
Created December 8, 2010 18:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mach3/733646 to your computer and use it in GitHub Desktop.
Save mach3/733646 to your computer and use it in GitHub Desktop.
Create association array from xml, usin domdocument.
<?php
// for example, from RSS
$dom = DOMDocument::loadXML( $string_stored_xml );
$entries = array();
foreach( $dom->getElementsByTagname("item") as $item ){
$entry = array();
foreach( $item->childNodes as $node ){
if( $node->nodeType === 1 ){
$entry[ $node->nodeName ] = $node->nodeValue;
}
}
array_push( $entries, $entry );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment