Advertisement
Guest User

Untitled

a guest
May 3rd, 2015
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. /**
  2. * Function returns XML string for input associative array.
  3. * @param Array $array Input associative array
  4. * @param String $wrap Wrapping tag
  5. * @param Boolean $upper To set tags in uppercase
  6. */
  7. function array2xml($array, $wrap='ROW0', $upper=true) {
  8. // set initial value for XML string
  9. $xml = '';
  10. // wrap XML with $wrap TAG
  11. if ($wrap != null) {
  12. $xml .= "<$wrap>\n";
  13. }
  14. // main loop
  15. foreach ($array as $key=>$value) {
  16. // set tags in uppercase if needed
  17. if ($upper == true) {
  18. $key = strtoupper($key);
  19. }
  20. // append to XML string
  21. $xml .= "<$key>" . htmlspecialchars(trim($value)) . "</$key>";
  22. }
  23. // close wrap TAG if needed
  24. if ($wrap != null) {
  25. $xml .= "\n</$wrap>\n";
  26. }
  27. // return prepared XML string
  28. return $xml;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement