setDelimiter(';'); $reader->stripBom(true); /*$contents = $reader->__toString(); if (!Utf8::isUtf8($contents)) { // If file is not in utf8 try converting to ISO-8859-15 if ($reader->getStreamFilterMode() == 1) { $reader->appendStreamFilter('convert.iconv.ISO-8859-15/UTF-8'); } }*/ $iterator = $reader->fetchAssoc(0); return iterator_to_array($iterator); } return []; } public static function csvColumnToArray($filename, $columnIndex = 0): array { if (empty($filename)) { return []; } $reader = Reader::createFromPath($filename, 'r'); if (!$reader) { return []; } $reader->setDelimiter(';'); $reader->stripBom(true); $iterator = $reader->fetchColumn($columnIndex); return iterator_to_array($iterator); } /** * @param string $filename * * @return array */ public static function xlsToArray($filename) { if (empty($filename)) { return []; } $file = new \SplFileObject($filename); return new ExcelReader($file, 0); } /** * @param string $file * * @return Crawler */ public static function xml($file) { return self::xmlFromString(file_get_contents($file)); } /** * @param string $contents * * @return Crawler */ public static function xmlFromString($contents) { @libxml_disable_entity_loader(true); $crawler = new Crawler(); $crawler->addXmlContent($contents); return $crawler; } }