Parsing XML with PHP - more than 1 child element

Hello guys,

First, thanks for providing the great tutorial at: http://www.kirupa.com/web/xml_php_parse_intermediate.htm

I don’t know much about XML or PHP, so this has helped me greatly with parsing an XML document into PHP variables and then into a database, which is what I need to do.

My problem is, that my XML file is formed like this:

<?xml version=“1.0” encoding=“utf-8”?>
<members>
<member>
<exchange_id>1</exchange_id>
<f_name>Test First 1</f_name>
<l_name>Test Last 1</l_name>
<job_title>Mr</job_title>
<email>test@test.com</email>
<categories>
<category>Test Category 1</category>
<category>Test Category 2</category>
<category>Test Category 3</category>
</categories>
</member>
<member>
<exchange_id>2</exchange_id>
<f_name>Test First 2</f_name>
<l_name>Test Last 2</l_name>
<job_title>Mr</job_title>
<email>test2@test2.com</email>
<categories>
<category>Test Category 1</category>
</categories>
</member>
</members>

etc etc…

Now, when there is only 1 category in the XML data, your script works perfectly. However, when there is more than 1 category in my XML data, it doesn’t work. What I want to do is put all 3 categories (or however many I have) into one variable, separated by commas, so the $category variable for the first piece of data might be “Test Category 1, Test Category 2, Test Category 3”

Hopefully this makes sense to you guys, any help would be greatly appreciated!!

Cheers,
Darryl