note 126814 added to function.xml-parser-create

From: Date: Mon, 31 Jan 2022 20:01:03 +0000
Subject: note 126814 added to function.xml-parser-create
Groups: php.notes 
Request: Send a blank email to php-notes+get-217559@lists.php.net to get a copy of this message
/* * 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 } ---- Server IP: 45.112.84.4 Probable Submitter: 80.90.5.135 (proxied: 37.214.77.172) ---- Manual Page -- https://php.net/manual/en/function.xml-parser-create.php Edit -- https://main.php.net/note/edit/126814 Del: integrated -- https://main.php.net/note/delete/126814/integrated Del: useless -- https://main.php.net/note/delete/126814/useless Del: bad code -- https://main.php.net/note/delete/126814/bad+code Del: spam -- https://main.php.net/note/delete/126814/spam Del: non-english -- https://main.php.net/note/delete/126814/non-english Del: in docs -- https://main.php.net/note/delete/126814/in+docs Del: other reasons-- https://main.php.net/note/delete/126814 Reject -- https://main.php.net/note/reject/126814 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#217559) next »