/** * Get the singular form of an English word. * * @param string $value * @return string */ public static function singular($value) { return Pluralizer::singular($value); }
public function toXML($data = null, $structure = null, $basenode = 'result') { if ($data === null and !func_num_args()) { $data = $this->_data; } // turn off compatibility mode as simple xml throws a wobbly if you don't. if (ini_get('zend.ze1_compatibility_mode') == 1) { ini_set('zend.ze1_compatibility_mode', 0); } if ($structure === null) { $structure = simplexml_load_string("<?xml version='1.0' encoding='utf-8'?><{$basenode} />"); } // Force it to be something useful if (!is_array($data) and !is_object($data)) { $data = (array) $data; } foreach ($data as $key => $value) { //change false/true to 0/1 if (is_bool($value)) { $value = (int) $value; } // no numeric keys in our xml please! if (is_numeric($key)) { // make string key... $key = Pluralizer::singular($basenode) != $basenode ? Pluralizer::singular($basenode) : 'item'; } // replace anything not alpha numeric $key = preg_replace('/[^a-z_\\-0-9]/i', '', $key); // if there is another array found recursively call this function if (is_array($value) or is_object($value)) { $node = $structure->addChild($key); // recursive call. $this->toXML($value, $node, $key); } else { // add single node. $value = htmlspecialchars(html_entity_decode($value, ENT_QUOTES, 'UTF-8'), ENT_QUOTES, "UTF-8"); $structure->addChild($key, $value); } } return $structure->asXML(); }