shadiadiph Posted June 12, 2010 Share Posted June 12, 2010 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: Link to comment https://forums.phpfreaks.com/topic/204562-how-to-insert-an-array-into-tags-and-preserve-it/ Share on other sites More sharing options...
ignace Posted June 12, 2010 Share Posted June 12, 2010 $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 https://forums.phpfreaks.com/topic/204562-how-to-insert-an-array-into-tags-and-preserve-it/#findComment-1071096 Share on other sites More sharing options...
shadiadiph Posted June 14, 2010 Author Share Posted June 14, 2010 thanks ignace Link to comment https://forums.phpfreaks.com/topic/204562-how-to-insert-an-array-into-tags-and-preserve-it/#findComment-1071710 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.