Location: PHPKode > scripts > Array 2 XML OO > array2xml-oo.php
<?php
class array2xml
{
	// version 0.1
	// coder: Mustafa Turan
	private $arr;

	public function __construct()
	{
		$this->arr = array();
	}

	public function __destruct()
	{
		$this->arr = null;
	}

	public function setArr($arr)
	{
		if(is_array($arr))
			$this->arr = $arr;
	}

	public function createXML()
	{
		$xml_data = '<?xml version="1.0" encoding="utf-8"?>';
		$xml_data .= '<domain>';
		$xml_data .= $this->array2_recursiveString($this->arr);
		$xml_data .= '</domain>';
		return $xml_data;
	}

	private function array2_recursiveString($arr){
		$str = '';
		if(is_array($arr)){
			foreach ($arr as $key=>$value){
				if(is_array($value)){
					if(is_numeric($key)) $key = "transaction";
					$str .= '<' . $key . '>';
					$str .= $this->array2_recursiveString($value);
					$str .= '</' . $key . '>';
				}
				else{
					$value = htmlspecialchars($value, ENT_QUOTES, 'UTF-8');		
					$str .= '<' . $key . '>' . $value . '</' . $key . '>';
				}
			}
		}
		return $str;
	}

}
?>
Return current item: Array 2 XML OO