$val) { if ($val != '') $items[$ii][$tags[$key]] = $val; } $ii++; } fclose($handle); if ($utf8_tmp) unlink($csvfile); $result = [ 'num' => count($items), 'tags' => $tags, 'rows' => $items ]; unset($tags, $items); return $result; } /* !Excel */ function Excel2Array($fname) { require_once(dirname(__FILE__).'/excel_reader.php'); $Excel = new Spreadsheet_Excel_Reader(); // создаем объект $Excel->setOutputEncoding('UTF-8'); // устанавливаем кодировку $Excel->read($fname); // открываем файл $tags = $Excel->sheets[0]['cells'][1]; // Определяем теги $items = []; $ii = 0; foreach ($Excel->sheets[0]['cells'] AS $key => $value) { if ($key == 1) continue; foreach($value AS $k => $val) { $items[$ii][$tags[$k]] = $val; } $ii++; } $result = [ 'num' => count($items), 'tags' => $tags, 'rows' => $items ]; unset($Excel, $tags, $items); return $result; } /* !XML */ function XML2Array($fname) { $xml = (simplexml_load_file($fname)); $xml = object2array($xml); unset ($xml['@attributes']); $a = array_values($xml); $tags = []; // Определяем теги foreach ($a[0][0] AS $key => $value) { $tags[] = $key; } $items = []; foreach ($a[0] AS $key => $row) { foreach($row AS $k => $val) { if ($val != '') $items[$key][$k] = $val; } } $result = [ 'num' => count($items), 'tags' => $tags, 'rows' => $items ]; unset($xml, $a, $tags, $items); return $result; } }