Code:
function print_xml_r($arr,$ wrapper = 'data',$cycle = 1) {
vars $new_line = "\n";
//start building content
if($cycle == 1) {
$output = '<?xml version="1.0"
encoding="UTF-8" ?>'.$new_line; }
$output.= tabify($cycle - 1).'<'.$ wrapper.'>'.$new_line; foreach($arr as $key => $val) {
if(!is_array($val)) {
$output.= tabify($cycle).'<'.htmlspecialchars($key).'>'.$ val.'</'.htmlspecialchars($key).'>'.$new_line;
}
else
{
$output.= print_xml_r($val,$ key,$cycle + 1).$new_line;
}
}
$output.= tabify($cycle - 1).'</'.$wrapper.'>';
//return the value
return isset($output)?$output:null;
}
/* tabify */
function tabify($num_tabs) { for($x = 1; $x <= $num_tabs; $x++) {
$return.= "\t";
}
return $return;
}
Code:
$_POST = array('first_name'=>'Shushant', 'last_name'=>'Kumar', 'url'=>'http://game143.com'', 'languages'=>array ('php','Jquery','Javascript',), 'title'=>'Web Developer', 'favorite_blogs'=>array ('Github'=>'http://github.com','C-Talk'=>'http://coding-talk.com',) ,);
echo print_xml_r($_POST);