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:

 

 

 

Link to comment
Share on other sites

$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>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.