Jump to content

how to insert an array into <xml></xml> tags and preserve it


shadiadiph

Recommended Posts

Is there any way I can insert an array into <xml></xml> tags and preserve it?

 

my problem is i have an array formatted like this 'AF' => 'Afghanistan', 'AX' => 'Aland Islands'  which gets inserted into <countries>$countries</countries> in my xml

 

so imploding it and exploding it doesn't work as i lose the key values.

 

I tried $countries .=$countries it sends the string accross and displays it on the xml reading page but then can't seem to turn it back into an array.

 

There is probably a simple solution to this but I can't think of it if i sent it without doing $countries .=$countries first it just sends the word Array accross.  :confused: :confused:

 

 

 

$root = $dom->createElement('countries');

foreach ($countries as $countryCode => $fullName) {
  $country = $dom->createElement('country', $fullName);
  $country->setAttribute('code', $countryCode);
  $root->addElement($country);
}

 

Generates:

 

<countries>

  <country code="AF">Afghanistan</country>

  <country code="AX">Aland Islands</country>

  ..

</countries>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.