Page 1 of 1

How to convert XML tags with attributes to array

Posted: Mon Jan 02, 2017 5:11 am
by juliasceasor
Hi,

I have a code snippet which stores the tags and value in an array (indexed). Please see below:

<foo>Test</foo>

$data['foo'] = 'Test';

But when I store the tag which has attributes as mentioned below, it does not accept.

<foo order='1'>Test</foo>

Array: $data['foo'] = array('_'=>'Test','order'=>'1'); //Referred from forums

But it sets the attributes and not actual data for the tag.

Please help me in this, how to do this.

Thanks & Regards,
Julias

Re: How to convert XML tags with attributes to array

Posted: Mon Jan 02, 2017 4:56 pm
by Celauran
juliasceasor wrote:I have a code snippet which stores the tags and value in an array (indexed).
Would help if you showed the code you were using.

That said, have you looked at SimpleXML and/or xml_parse_into_struct?