function print_r_xml($arr,$wrapper="data",$cycle = 1)
{
//useful 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_r_xml($val,$key,$cycle + 1).$new_line;
}
}
$output.= tabify($cycle - 1).'</'.$wrapper.'>';
//return the value
return $output;
}
/* tabify */
function tabify($num_tabs)
{
for($x = 1; $x <= $num_tabs; $x++) { $return.= "\t"; }
return $return;
}
/* test */
$_POST = array(
'first_name'=>'Faruq',
'last_name'=>'Shaik',
'url'=>'http://faruq1256.blogspot.com',
'languages'=>array('php','javascript','Python','Ruby'),
'title'=>'Web Developer',
'favorite'=>array('PHP'=>'http://php.net','Jquery'=>'http://jquery.com')
);
echo print_r_xml($_POST);
No comments:
Post a Comment