common.inc 851 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. function array_to_xml($array, $skip_top_closing=false, $level=0)
  3. {
  4. static $result="<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n";
  5. foreach($array as $k => $v)
  6. {
  7. if(is_numeric($k))
  8. array_to_xml($v, $skip_top_closing, $level);
  9. else
  10. {
  11. for($j=0; $j<$level; $j++)
  12. $result.=" ";
  13. $result.="<".htmlspecialchars($k);
  14. if($k=='resources')
  15. $result.=" xmlns=\"urn:com.inf-it:configuration\"";
  16. if($v=='')
  17. $result.=" />\n";
  18. else
  19. {
  20. $result.=">";
  21. if(is_array($v))
  22. {
  23. $result.="\n";
  24. array_to_xml($v, $skip_top_closing, $level+1);
  25. for($j=0; $j<$level; $j++)
  26. $result.=" ";
  27. }
  28. else
  29. $result.=htmlspecialchars($v);
  30. if($level!==0 || $skip_top_closing===false)
  31. $result.="</".htmlspecialchars($k).">\n";
  32. }
  33. }
  34. }
  35. return $result;
  36. }
  37. ?>