<?php
class array2xml {
	var $xml;
	function array2xml($array, $encoding = 'gb2312') {
		$this -> xml = '<?xml version="1.0" encoding="' . $encoding . '"?><root>';
		$this -> xml .= $this -> _array2xml($array);
	} 
	function get() {
		return $this -> xml . "</root>";
	} 
	function _array2xml($array) {
		foreach($array as $key => $val) {
			is_numeric($key) && $key = "item id=\"$key\"";
			$xml .= "<$key>";
			$xml .= is_array($val)?$this -> _array2xml($val):$val;
			list($key,) = explode(' ', $key);
			$xml .= "</$key>";
		} 
		return $xml;
	} 
} 

?>