public function testNoHeaderCsv() { $csvParser = new csvParser(dirname(__FILE__) . "/testCsv/noHeader.csv", false); $data = $csvParser->getNext(); $etalon = array(array("val1", "val2", 123)); $this->assertEquals($etalon, $data); }
$file_location = 'wp-content/uploads/' . $file; $file = fopen($file_location, 'r'); } else { print "no file at {$file_location}"; die; } if ($file) { while (($line = fgetcsv($file)) !== FALSE) { $number_of_columns = count($line); $array[] = $line; } $headers = $array['0']; // get first row for headers used in a foreach below. } if ($file) { $parser = new csvParser(); $data_set = $parser->parseFile($file_location); } if ($file) { fclose($file); } $output = ''; foreach ($data_set as $rows) { $output .= " { "; foreach ($rows as $key => $value_prepared) { $value_prepared = str_replace("’", "'", $value_prepared); $value_prepared = str_replace(":", "-", $value_prepared); $value_prepared = trim($value_prepared); $output .= "{$key} : '{$value_prepared}', "; } $output .= " }, " . PHP_EOL;