note 126813 deleted from function.xml-parser-create by cmb

From: Date: Mon, 31 Jan 2022 20:37:03 +0000
Subject: note 126813 deleted from function.xml-parser-create by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-217561@lists.php.net to get a copy of this message
Note Submitter: anton dot zhavrid dot minsk at gmail dot com ---- /* * function for parse xml and return it in array */ function xml_to_object($xml) { $parser = xml_parser_create(); xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); xml_parse_into_struct($parser, $xml, $tags); xml_parser_free($parser); $elements = array(); // the currently filling [child] XmlElement array $stack = array(); foreach ($tags as $tag) { $index = count($elements); if ($tag['type'] == "complete" || $tag['type'] == "open") { $elements[$index]['title'] = $tag['tag']; if($tag['attributes']["idDoc"] != null) { $elements[$index]['idDoc'] = $tag['attributes']["idDoc"]; } $elements[$index]['attributes'] = $tag['attributes']; $elements[$index]['content'] = $tag['value']; if ($tag['type'] == "open") { // push $elements[$index]['children'] = array(); $elements[$index]['folder'] = true; $stack[count($stack)] = &$elements; $elements = &$elements[$index]['children']; } } if ($tag['type'] == "close") { // pop $elements = &$stack[count($stack) - 1]; unset($stack[count($stack) - 1]); } } return $elements; // the single top-level element }

« previous php.notes (#217561) next »