XML to PHP array - here's more info

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

XML to PHP array - here's more info

Post by patrikG »

Yes, there are commercial solutions, and yes, in PHP 5 the DOM will be nice & cosy with XML, but for now extracting data from XML with PHP is a bit of a pain - a bit.

There is a nice and illuminating article on this which explains it quite clearly - so if you need to do this stuff (I am not talking about generating XML with PHP, but parsing), maybe you find this helpful as well:

http://www.devarticles.com/c/a/PHP/Conv ... Structure/
User avatar
scorphus
Forum Regular
Posts: 589
Joined: Fri May 09, 2003 11:53 pm
Location: Belo Horizonte, Brazil
Contact:

Post by scorphus »

Many thanks, patrickG. Very nice article.
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

Hmm...there is actually a PHP function that parses an xml-file into an array - although a darstardly one which doesn't mirror the parent-child relationships of the xml-document.
[php_man]xml_parse_into_struct[/php_man]

It's not beautiful and after playing around with it for a couple of days I wouldn't recommend it. Rather use one of the functions provided in the user-notes to generate a proper multidimensional array - provided you don't have server-access and can't install expat (PHP's xpath library).
Post Reply