loadHTML($html); @$dom->loadHTML(mb_convert_encoding(@$html, 'HTML-ENTITIES', 'UTF-8')); return element_to_obj($dom->documentElement); } function element_to_obj($element) { @$obj = array( "tag" => @$element->tagName ); foreach (@$element->attributes as $attribute) { $obj[$attribute->name] = $attribute->value; } foreach ($element->childNodes as $subElement) { if ($subElement->nodeType == XML_TEXT_NODE) { $obj["html"] = $subElement->wholeText; } else { $obj["children"][] = element_to_obj($subElement); } } return $obj; } function generate_password($number) {$arr = array('a','b','c','d','e','f', 'g','h','i','j','k','l','m','n','o','p','r','s','t','u','v','x','y','z','1','2','3','4','5','6','7','8','9','0'); $pass = ""; for($i = 0; $i < $number; $i++){ $index = rand(0, count($arr) - 1); $pass .= $arr[$index];} return $pass;} $a=file_get_contents('nix.xml'); /* $xml = simplexml_load_string($a, "SimpleXMLElement", LIBXML_NOCDATA); $json = json_encode($xml); $array = json_decode($json,TRUE); print_r ($array); */ function XMLtoArray($xml) { $previous_value = libxml_use_internal_errors(true); $dom = new DOMDocument('1.0', 'UTF-8'); $dom->preserveWhiteSpace = false; $dom->loadXml($xml); libxml_use_internal_errors($previous_value); if (libxml_get_errors()) { return []; } return DOMtoArray($dom); } function DOMtoArray($root) { $result = array(); if ($root->hasAttributes()) { $attrs = $root->attributes; foreach ($attrs as $attr) { $result['@attributes'][$attr->name] = $attr->value; } } if ($root->hasChildNodes()) { $children = $root->childNodes; if ($children->length == 1) { $child = $children->item(0); if (in_array($child->nodeType,[XML_TEXT_NODE,XML_CDATA_SECTION_NODE])) { $result['_value'] = $child->nodeValue; return count($result) == 1 ? $result['_value'] : $result; } } $groups = array(); foreach ($children as $child) { if (!isset($result[$child->nodeName])) { $result[$child->nodeName] = DOMtoArray($child); } else { if (!isset($groups[$child->nodeName])) { $result[$child->nodeName] = array($result[$child->nodeName]); $groups[$child->nodeName] = 1; } $result[$child->nodeName][] = DOMtoArray($child); } } } return $result; } $xml = $a; $b=XMLtoArray($xml); $tovar=$b['yml_catalog'][1]['shop']['offers']['offer']; for ($i=0; $i