DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Parsing An RSS Feed For All Post Titles

02.28.2007
| 2634 views |
  • submit to reddit
        // 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;
}