function CMBase::array2xml in Campaign Monitor 6.2
Same name and namespace in other branches
- 6.3 lib/CMBase.php \CMBase::array2xml()
* Converts an array to XML. This is the inverse to xml2array(). Values * are automatically escaped with htmlentities(), so you don't need to escape * values ahead of time. If you have, just set the third parameter to false. * This is an all-or-nothing deal. * *
Parameters
mixed $arr The associative to convert to an XML fragment: * @param string $indent (Optional) Starting identation of each element * @param string $escape (Optional) Determines whether or not to escape a text node. * @return string An XML fragment.
1 call to CMBase::array2xml()
- CMBase::makeCall in lib/
CMBase.php - * The direct way to make an API call. This allows developers to include new API * methods that might not yet have a wrapper method as part of the package. * *
File
- lib/
CMBase.php, line 490
Class
Code
function array2xml($arr, $indent = '', $escape = true) {
$buff = '';
foreach ($arr as $k => $v) {
if (!is_array($v)) {
$buff .= "{$indent}<{$k}>" . ($escape ? utf8_encode($v) : $v) . "</{$k}>\n";
}
else {
/*
Encountered a list. The primary difference between the two branches is that
in the 'if' branch, a $k element is generated for each item in $v, whereas
in the 'else' branch, a single $k element encapsulates $v.
*/
if (isset($v[0])) {
foreach ($v as $_k => $_v) {
if (is_array($_v)) {
$buff .= "{$indent}<{$k}>\n" . $this
->array2xml($_v, $indent . "\t", $escape) . "{$indent}</{$k}>\n";
}
else {
$buff .= "{$indent}<{$k}>" . ($escape ? utf8_encode($_v) : $_v) . "</{$k}>\n";
}
}
}
else {
$buff .= "{$indent}<{$k}>\n" . $this
->array2xml($v, $indent . "\t", $escape) . "{$indent}</{$k}>\n";
}
}
}
return $buff;
}