login about faq

Due to the large amount of spam accounts, we temporarily disabled new user sign ups. To override this, email newuser.lgqa@gmail.com and an admin will determine if you are permitted to join


I need a function that takes a string as XML input and change that into an array. Example:

<a>
 <b>
  <c></c>
 </b>
</a>

So I can read it in PHP like this:

$array = xml2array($xmlcode);
echo $array['a']['b']['c'];

Note: I tried all xml2array functions in PHP's documentation on xml_parse, and they all didn't work or had problems.

asked Jun 03 '10 at 18:31

Ang's gravatar image

Ang
4.5k134176


Try this one.

answered Jun 03 '10 at 18:34

tsilb's gravatar image

tsilb
21.0k65199333

Gives same problems as I had before:

Notice: Array to string conversion in /srv/www/htdocs/xml2.php on line 102

Fatal error: Cannot use string offset as an array in /srv/www/htdocs/xml2.php on line 107

After parsing a few XML documents that error pops up.

(Jun 03 '10 at 18:39) Ang Ang's gravatar image

Sorry, don't know PHP.

(Jun 03 '10 at 18:42) tsilb tsilb's gravatar image
(Jun 03 '10 at 18:43) tsilb tsilb's gravatar image

An array is a type that typically requires an integer index. It sounds to me as though you want something that outputs specifically in the form of an associative array. Try this. Hope this helps :)

answered Jul 10 '10 at 18:14

Seb's gravatar image

Seb
(suspended)

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported


Join Us in the Chat Room

Tags:

×125
×96
×11
×7

Asked: Jun 03 '10 at 18:31

Seen: 1,920 times

Last updated: Jul 10 '10 at 18:14