Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Function returns XML string for input associative array.
- * @param Array $array Input associative array
- * @param String $wrap Wrapping tag
- * @param Boolean $upper To set tags in uppercase
- */
- function array2xml($array, $wrap='ROW0', $upper=true) {
- // set initial value for XML string
- $xml = '';
- // wrap XML with $wrap TAG
- if ($wrap != null) {
- $xml .= "<$wrap>\n";
- }
- // main loop
- foreach ($array as $key=>$value) {
- // set tags in uppercase if needed
- if ($upper == true) {
- $key = strtoupper($key);
- }
- // append to XML string
- $xml .= "<$key>" . htmlspecialchars(trim($value)) . "</$key>";
- }
- // close wrap TAG if needed
- if ($wrap != null) {
- $xml .= "\n</$wrap>\n";
- }
- // return prepared XML string
- return $xml;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement