function addCDATA(&$array, $depth = 0) { foreach ($array as $aId => $child) { if ((string) $aId == '@attributes') { continue; } if (!is_array($child) && trim((string) $child) != '') { $array[$aId] = '<![CDATA[' . $child . ']]>'; } //echo $child . ', ' . count($child->children()) . "\r\n"; // echo str_repeat('-',$depth).">".$child->getName().": ".$subchild."<br />"; if (is_array($array[$aId])) { Array_XML::addCDATA($array[$aId], $depth + 1); } } }
public static function saveTags($tags, $sectionsList = false) { $arrayToSave = array('section' => array()); foreach ($tags as $sName => $s) { if (!$sectionsList || isset($sectionsList[$sName])) { $sectionTags = array(); $c = 0; foreach ($s as $tName => $t) { $sectionTags[] = array('@attributes' => array('name' => $tName, 'entry_count' => $t['entry_count']), 'value' => $t['title']); $c += (int) $t['entry_count']; } $arrayToSave['section'][] = array('@attributes' => array('name' => $sName, 'entry_count' => $c), 'tag' => $sectionTags); } } Array_XML::addCDATA($arrayToSave); if ($xml = Array_XML::array2xml($arrayToSave, 'sections')) { $fileName = self::$options['XML_ROOT'] . self::$options['tags.xml']; if (@file_put_contents($fileName, $xml)) { @chmod($fileName, 0666); return true; } } return false; }