$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 = array(); $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 = array(); // Определяем теги foreach ($a[0][0] AS $key => $value) { $tags[] = $key; } $items = array(); 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; } /* !DBF */ public static function DBF2Array($fname) { $db = dbase_open($fname, 0); $cols = dbase_get_header_info($db); $count = dbase_numrecords($db); $rows = array(); $tags = array(); foreach($cols AS $k => $v) { $tags[] = $v['name']; } $ii = 1; for ($ii; $ii <= $count; $ii++) { $rows[] = dbase_get_record_with_names($db, $ii); } $result = [ 'num' => $count - $parser_row, 'tags' => $tags, 'rows' => $rows ]; dbase_close($db); unset($cols, $count, $tags, $rows); return $result; } }