public function testEscape() { $config = new LexerConfig(); $this->assertSame('\\', $config->getEscape()); $this->assertSame('esc', $config->setEscape('esc')->getEscape()); }
/** * CSV parser * * @param string $file Path of the file. * @return array Returns the array from csv. * @since 0.1.0 */ public static function csv_parser($csv_file) { if (!is_file($csv_file)) { return new WP_Error('error', 'The CSV file is not found.'); } elseif (!self::is_textfile($csv_file)) { return new WP_Error('error', 'The file is not CSV.'); } $csv = array(); /** * Filter the CSV setting for the csv parser. * * @param array settings for the csv parser. */ $format = apply_filters('acsv_csv_format', array('from_charset' => 'UTF-8', 'to_charset' => 'UTF-8', 'delimiter' => ',', 'enclosure' => '"', 'escape' => '\\')); $config = new LexerConfig(); $config->setFromCharset($format['from_charset']); $config->setToCharset($format['to_charset']); $config->setDelimiter($format['delimiter']); $config->setEnclosure($format['enclosure']); $config->setEscape($format['escape']); $lexer = new Lexer($config); $interpreter = new Interpreter(); $interpreter->unstrict(); $interpreter->addObserver(function (array $row) use(&$csv) { $csv[] = $row; }); $lexer->parse($csv_file, $interpreter); return $csv; }