Over a million developers have joined DZone.

Parsing An RSS Feed For All Post Titles

·
// description of your code here
http://www.thinkingphp.org/2007/02/24/cake-12s-set-class-eats-arrays-for-breakfast/


PHP:

function xmltoArray($node)
{
    $array = array();
    
    foreach ($node->children as $child)
    {
        if (empty($child->children))
        {
            $value = $child->value;
        }
        else
        {
            $value = xmltoArray($child);
        }
        
        $key = $child->name;
        
        if (!isset($array[$key]))
        {
            $array[$key] = $value;
        }
        else 
        {
            if (!is_array($array[$key]) || !isset($array[$key][0]))
            {
                $array[$key] = array($array[$key]);
            }
            
            $array[$key][] = $value;
        }
    }
    
    return $array;
} 
Topics:

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}