*/
function discoverFormat($filename)
{
- return File_CSV::discoverFormat($filename);
+ return Horde_File_Csv::discoverFormat($filename);
}
/**
* @return array A two-dimensional array of all imported data rows. If
* $header was true the rows are associative arrays with the
* field/column names as the keys.
+ *@throws Horde_File_Csv_Exception
*/
function importFile($filename, $header = false, $sep = '', $quote = '',
$fields = null, $import_mapping = array(),
$charset = null, $crlf = null)
{
- /* File_CSV is a bit picky at what parameters it expects. */
+ /* Horde_File_Csv is a bit picky at what parameters it expects. */
$conf = array();
if ($fields) {
$conf['fields'] = $fields;
/* Strip and keep the first line if it contains the field
* names. */
if ($header) {
- $head = File_CSV::read($filename, $conf);
- if (is_a($head, 'PEAR_Error')) {
- return $head;
- }
+ $head = Horde_File_Csv::read($filename, $conf);
if (!empty($charset)) {
$head = Horde_String::convertCharset($head, $charset, Horde_Nls::getCharset());
}
}
$data = array();
- while ($line = File_CSV::read($filename, $conf)) {
- if (is_a($line, 'PEAR_Error')) {
- return $line;
- }
+ while ($line = Horde_File_Csv::read($filename, $conf)) {
if (!empty($charset)) {
$line = Horde_String::convertCharset($line, $charset, Horde_Nls::getCharset());
}
}
}
- $fp = File_CSV::getPointer($filename, $conf);
- if ($fp && !is_a($fp, 'PEAR_Error')) {
+ $fp = Horde_File_Csv::getPointer($filename, $conf);
+ if ($fp) {
rewind($fp);
}
- $this->_warnings = File_CSV::warning();
+ $this->_warnings = Horde_File_Csv::warning();
return $data;
}
+++ /dev/null
-<?php
-/**
- * @package File_CSV
- */
-
-/** Mode to use for reading from files */
-define('HORDE_FILE_CSV_MODE_READ', 'rb');
-
-/** Mode to use for truncating files, then writing */
-define('HORDE_FILE_CSV_MODE_WRITE', 'wb');
-
-/** Mode to use for appending to files */
-define('HORDE_FILE_CSV_MODE_APPEND', 'ab');
-
-/**
- * The File_CSV package allows reading and creating of CSV data and files.
- *
- * Copyright 2002-2003 Tomas Von Veschler Cox <cox@idecnet.com>
- * Copyright 2005-2010 The Horde Project (http://www.horde.org/)
- *
- * This source file is subject to version 2.0 of the PHP license, that is
- * bundled with this package in the file LICENSE, and is available at through
- * the world-wide-web at http://www.php.net/license/2_02.txt. If you did not
- * receive a copy of the PHP license and are unable to obtain it through the
- * world-wide-web, please send a note to license@php.net so we can mail you a
- * copy immediately.
- *
- * @author Tomas Von Veschler Cox <cox@idecnet.com>
- * @author Jan Schneider <jan@horde.org>
- * @package File_CSV
- */
-class File_CSV {
-
- /**
- * Discovers the format of a CSV file (the number of fields, the separator,
- * the quote string, and the line break).
- *
- * We can't use the auto_detect_line_endings PHP setting, because it's not
- * supported by fgets() contrary to what the manual says.
- *
- * @static
- *
- * @param string The CSV file name
- * @param array Extra separators that should be checked for.
- *
- * @return array The format hash.
- */
- function discoverFormat($file, $extraSeps = array())
- {
- if (!$fp = @fopen($file, 'r')) {
- return PEAR::raiseError('Could not open file: ' . $file);
- }
-
- $seps = array("\t", ';', ':', ',', '~');
- $seps = array_merge($seps, $extraSeps);
- $matches = array();
- $crlf = null;
- $conf = array();
-
- /* Take the first 10 lines and store the number of ocurrences for each
- * separator in each line. */
- for ($i = 0; ($i < 10) && ($line = fgets($fp));) {
- /* Do we have Mac line endings? */
- $lines = preg_split('/\r(?!\n)/', $line, 10);
- $j = 0;
- $c = count($lines);
- if ($c > 1) {
- $crlf = "\r";
- }
- while ($i < 10 && $j < $c) {
- $line = $lines[$j];
- if (!isset($crlf)) {
- foreach (array("\r\n", "\n") as $c) {
- if (substr($line, -strlen($c)) == $c) {
- $crlf = $c;
- break;
- }
- }
- }
- $i++;
- $j++;
- foreach ($seps as $sep) {
- $matches[$sep][$i] = substr_count($line, $sep);
- }
- }
- }
- if (isset($crlf)) {
- $conf['crlf'] = $crlf;
- }
-
- /* Group the results by amount of equal occurrences. */
- $fields = array();
- $amount = array();
- foreach ($matches as $sep => $lines) {
- $times = array();
- $times[0] = 0;
- foreach ($lines as $num) {
- if ($num > 0) {
- $times[$num] = (isset($times[$num])) ? $times[$num] + 1 : 1;
- }
- }
- arsort($times);
- $fields[$sep] = key($times);
- $amount[$sep] = $times[key($times)];
- }
- arsort($amount);
- $sep = key($amount);
-
- $conf['fields'] = $fields[$sep] + 1;
- $conf['sep'] = $sep;
-
- /* Test if there are fields with quotes around in the first 10
- * lines. */
- $quotes = '"\'';
- $quote = '';
- rewind($fp);
- for ($i = 0; ($i < 10) && ($line = fgets($fp)); $i++) {
- if (preg_match("|$sep([$quotes]).*([$quotes])$sep|U", $line, $match)) {
- if ($match[1] == $match[2]) {
- $quote = $match[1];
- break;
- }
- }
- if (preg_match("|^([$quotes]).*([$quotes])$sep|", $line, $match) ||
- preg_match("|([$quotes]).*([$quotes])$sep\s$|Us", $line, $match)) {
- if ($match[1] == $match[2]) {
- $quote = $match[1];
- break;
- }
- }
- }
- $conf['quote'] = $quote;
-
- fclose($fp);
-
- // XXX What about trying to discover the "header"?
- return $conf;
- }
-
- /**
- * Reads a row from a CSV file and returns it as an array.
- *
- * This method normalizes linebreaks to single newline characters (0x0a).
- *
- * @param string $file The name of the CSV file.
- * @param array $conf The configuration for the CSV file.
- *
- * @return array|boolean The CSV data or false if no more data available.
- */
- function read($file, &$conf)
- {
- $fp = File_CSV::getPointer($file, $conf, HORDE_FILE_CSV_MODE_READ);
- if (is_a($fp, 'PEAR_Error')) {
- return $fp;
- }
-
- $line = fgets($fp);
- $line_length = strlen($line);
-
- /* Use readQuoted() if we have Mac line endings. */
- if (preg_match('/\r(?!\n)/', $line)) {
- fseek($fp, -$line_length, SEEK_CUR);
- return File_CSV::readQuoted($file, $conf);
- }
-
- /* Normalize line endings. */
- $line = str_replace("\r\n", "\n", $line);
- if (!strlen(trim($line))) {
- return false;
- }
-
- File_CSV::_line(File_CSV::_line() + 1);
-
- if ($conf['fields'] == 1) {
- return array($line);
- }
-
- $fields = explode($conf['sep'], $line);
- if ($conf['quote']) {
- $last = ltrim($fields[count($fields) - 1]);
- /* Fallback to read the line with readQuoted() if we assume that
- * the simple explode won't work right. */
- $last_len = strlen($last);
- if (($last_len &&
- $last[$last_len - 1] == "\n" &&
- $last[0] == $conf['quote'] &&
- $last[strlen(rtrim($last)) - 1] != $conf['quote']) ||
- (count($fields) != $conf['fields'])
- // XXX perhaps there is a separator inside a quoted field
- // preg_match("|{$conf['quote']}.*{$conf['sep']}.*{$conf['quote']}|U", $line)
- ) {
- fseek($fp, -$line_length, SEEK_CUR);
- return File_CSV::readQuoted($file, $conf);
- } else {
- foreach ($fields as $k => $v) {
- $fields[$k] = File_CSV::unquote(trim($v), $conf['quote']);
- }
- }
- } else {
- foreach ($fields as $k => $v) {
- $fields[$k] = trim($v);
- }
- }
-
- if (count($fields) < $conf['fields']) {
- File_CSV::warning(sprintf(_("Wrong number of fields in line %d. Expected %d, found %d."), File_CSV::_line(), $conf['fields'], count($fields)));
- $fields = array_merge($fields, array_fill(0, $conf['fields'] - count($fields), ''));
- } elseif (count($fields) > $conf['fields']) {
- File_CSV::warning(sprintf(_("More fields found in line %d than the expected %d."), File_CSV::_line(), $conf['fields']));
- array_splice($fields, $conf['fields']);
- }
-
- return $fields;
- }
-
- /**
- * Reads a row from a CSV file and returns it as an array.
- *
- * This method is able to read fields with multiline data and normalizes
- * linebreaks to single newline characters (0x0a).
- *
- * @param string $file The name of the CSV file.
- * @param array $conf The configuration for the CSV file.
- *
- * @return array|boolean The CSV data or false if no more data available.
- */
- function readQuoted($file, &$conf)
- {
- $fp = File_CSV::getPointer($file, $conf, HORDE_FILE_CSV_MODE_READ);
- if (is_a($fp, 'PEAR_Error')) {
- return $fp;
- }
-
- /* A buffer with all characters of the current field read so far. */
- $buff = '';
- /* The current character. */
- $c = null;
- /* The read fields. */
- $ret = false;
- /* The number of the current field. */
- $i = 0;
- /* Are we inside a quoted field? */
- $in_quote = false;
- /* Did we just process an escaped quote? */
- $quote_escaped = false;
- /* Is the last processed quote the first of a field? */
- $first_quote = false;
-
- while (($ch = fgetc($fp)) !== false) {
- /* Normalize line breaks. */
- if ($ch == $conf['crlf']) {
- $ch = "\n";
- } elseif (strlen($conf['crlf']) == 2 && $ch == $conf['crlf'][0]) {
- $next = fgetc($fp);
- if (!$next) {
- break;
- }
- if ($next == $conf['crlf'][1]) {
- $ch = "\n";
- }
- }
-
- /* Previous character. */
- $prev = $c;
- /* Current character. */
- $c = $ch;
-
- /* Simple character. */
- if ($c != $conf['quote'] &&
- $c != $conf['sep'] &&
- $c != "\n") {
- $buff .= $c;
- if (!$i) {
- $i = 1;
- }
- $quote_escaped = false;
- $first_quote = false;
- continue;
- }
-
- if ($c == $conf['quote'] && !$in_quote) {
- /* Quoted field begins. */
- $in_quote = true;
- $buff = '';
- if (!$i) {
- $i = 1;
- }
- } elseif ($in_quote) {
- /* We do NOT check for the closing quote immediately, but when
- * we got the character AFTER the closing quote. */
- if ($c == $conf['quote'] && $prev == $conf['quote'] &&
- !$quote_escaped) {
- /* Escaped (double) quotes. */
- $quote_escaped = true;
- $first_quote = true;
- $prev = null;
- /* Simply skip the second quote. */
- continue;
- } elseif ($c == $conf['sep'] && $prev == $conf['quote']) {
- /* Quoted field ends with a delimiter. */
- $in_quote = false;
- $quote_escaped = false;
- $first_quote = true;
- } elseif ($c == "\n") {
- /* We have a linebreak inside the quotes. */
- if (strlen($buff) == 1 &&
- $buff[0] == $conf['quote'] &&
- $quote_escaped && $first_quote) {
- /* A line break after a closing quote of an empty
- * field, field and row end here. */
- $in_quote = false;
- } elseif (strlen($buff) >= 1 &&
- $buff[strlen($buff) - 1] == $conf['quote'] &&
- !$quote_escaped && !$first_quote) {
- /* A line break after a closing quote, field and row
- * end here. This is NOT the closing quote if we
- * either process an escaped (double) quote, or if the
- * quote before the line break was the opening
- * quote. */
- $in_quote = false;
- } else {
- /* Only increment the line number. Line breaks inside
- * quoted fields are part of the field content. */
- File_CSV::_line(File_CSV::_line() + 1);
- }
- $quote_escaped = false;
- $first_quote = true;
- }
- }
-
- if (!$in_quote &&
- ($c == $conf['sep'] || $c == "\n")) {
- /* End of line or end of field. */
- if ($c == $conf['sep'] &&
- (count($ret) + 1) == $conf['fields']) {
- /* More fields than expected. Forward the line pointer to
- * the EOL and drop the remainder. */
- while ($c !== false && $c != "\n") {
- $c = fgetc($fp);
- }
- File_CSV::warning(sprintf(_("More fields found in line %d than the expected %d."), File_CSV::_line(), $conf['fields']));
- }
-
- if ($c == "\n" &&
- $i != $conf['fields']) {
- /* Less fields than expected. */
- if ($i == 0) {
- /* Skip empty lines. */
- return $ret;
- }
- File_CSV::warning(sprintf(_("Wrong number of fields in line %d. Expected %d, found %d."), File_CSV::_line(), $conf['fields'], $i));
-
- $ret[] = File_CSV::unquote($buff, $conf['quote']);
- $ret = array_merge($ret, array_fill(0, $conf['fields'] - $i, ''));
- return $ret;
- }
-
- /* Remove surrounding quotes from quoted fields. */
- if ($buff == '"') {
- $ret[] = '';
- } else {
- $ret[] = File_CSV::unquote($buff, $conf['quote']);
- }
- if (count($ret) == $conf['fields']) {
- return $ret;
- }
-
- $buff = '';
- $i++;
- continue;
- }
- $buff .= $c;
- }
-
- return $ret;
- }
-
- /**
- * Writes a hash into a CSV file.
- *
- * @param string $file The name of the CSV file.
- * @param array $fields The CSV data.
- * @param array $conf The configuration for the CSV file.
- *
- * @return boolean True on success, PEAR_Error on failure.
- */
- function write($file, $fields, &$conf)
- {
- if (is_a($fp = File_CSV::getPointer($file, $conf, HORDE_FILE_CSV_MODE_WRITE), 'PEAR_Error')) {
- return $fp;
- }
-
- if (count($fields) != $conf['fields']) {
- return PEAR::raiseError(sprintf(_("Wrong number of fields. Expected %d, found %d."), $conf['fields'], count($fields)));
- }
-
- $write = '';
- for ($i = 0; $i < count($fields); $i++) {
- if (!is_numeric($fields[$i]) && $conf['quote']) {
- $write .= $conf['quote'] . $fields[$i] . $conf['quote'];
- } else {
- $write .= $fields[$i];
- }
- if ($i < (count($fields) - 1)) {
- $write .= $conf['sep'];
- } else {
- $write .= $conf['crlf'];
- }
- }
-
- if (!fwrite($fp, $write)) {
- return PEAR::raiseError(sprintf(_("Cannot write to file \"%s\""), $file));
- }
-
- return true;
- }
-
- /**
- * Removes surrounding quotes from a string and normalizes linebreaks.
- *
- * @param string $field The string to unquote.
- * @param string $quote The quote character.
- * @param string $crlf The linebreak character.
- *
- * @return string The unquoted data.
- */
- function unquote($field, $quote, $crlf = null)
- {
- /* Skip empty fields (form: ;;) */
- if (!strlen($field)) {
- return $field;
- }
- if ($quote && $field[0] == $quote &&
- $field[strlen($field) - 1] == $quote) {
- /* Normalize only for BC. */
- if ($crlf) {
- $field = str_replace($crlf, "\n", $field);
- }
- return substr($field, 1, -1);
- }
- return $field;
- }
-
- /**
- * Sets or gets the current line being parsed.
- *
- * @param integer $line If specified, the current line.
- *
- * @return integer The current line.
- */
- function _line($line = null)
- {
- static $current_line = 0;
-
- if (!is_null($line)) {
- $current_line = $line;
- }
-
- return $current_line;
- }
-
- /**
- * Adds a warning to or retrieves and resets the warning stack.
- *
- * @param string A warning string. If not specified, the existing
- * warnings will be returned instead and the warning stack
- * gets emptied.
- *
- * @return array If no parameter has been specified, the list of existing
- * warnings.
- */
- function warning($warning = null)
- {
- static $warnings = array();
-
- if (is_null($warning)) {
- $return = $warnings;
- $warnings = array();
- return $return;
- }
-
- $warnings[] = $warning;
- }
-
- /**
- * Returns or creates the file descriptor associated with a file.
- *
- * @static
- *
- * @param string $file The name of the file
- * @param array $conf The configuration
- * @param string $mode The open mode. HORDE_FILE_CSV_MODE_READ or
- * HORDE_FILE_CSV_MODE_WRITE.
- *
- * @return resource The file resource or PEAR_Error on error.
- */
- function getPointer($file, &$conf, $mode = HORDE_FILE_CSV_MODE_READ)
- {
- static $resources = array();
- static $config = array();
-
- if (isset($resources[$file])) {
- $conf = $config[$file];
- return $resources[$file];
- }
- if (is_a($error = File_CSV::_checkConfig($conf), 'PEAR_Error')) {
- return $error;
- }
- $config[$file] = $conf;
-
- $fp = @fopen($file, $mode);
- if (!is_resource($fp)) {
- return PEAR::raiseError(sprintf(_("Cannot open file \"%s\"."), $file));
- }
- $resources[$file] = $fp;
- File_CSV::_line(0);
-
- if ($mode == HORDE_FILE_CSV_MODE_READ && !empty($conf['header'])) {
- if (is_a($header = File_CSV::read($file, $conf), 'PEAR_Error')) {
- return $header;
- }
- }
-
- return $fp;
- }
-
- /**
- * Checks the configuration given by the user.
- *
- * @param array $conf The configuration assoc array
- * @param string $error The error will be written here if any
- */
- function _checkConfig(&$conf)
- {
- // check conf
- if (!is_array($conf)) {
- return PEAR::raiseError('Invalid configuration.');
- }
-
- if (!isset($conf['fields']) || !is_numeric($conf['fields'])) {
- return PEAR::raiseError(_("The number of fields must be numeric."));
- }
-
- if (isset($conf['sep'])) {
- if (strlen($conf['sep']) != 1) {
- return PEAR::raiseError(_("The separator must be one single character."));
- }
- } elseif ($conf['fields'] > 1) {
- return PEAR::raiseError(_("No separator specified."));
- }
-
- if (!empty($conf['quote'])) {
- if (strlen($conf['quote']) != 1) {
- return PEAR::raiseError(_("The quote character must be one single character."));
- }
- } else {
- $conf['quote'] = '';
- }
-
- if (!isset($conf['crlf'])) {
- $conf['crlf'] = "\n";
- }
- }
-
-}
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<package packagerversion="1.4.9" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0
-http://pear.php.net/dtd/tasks-1.0.xsd
-http://pear.php.net/dtd/package-2.0
-http://pear.php.net/dtd/package-2.0.xsd">
- <name>File_CSV</name>
- <channel>pear.horde.org</channel>
- <summary>Reads and writes CSV files</summary>
- <description>The File_CSV package allows reading and creating of CSV data and files. It
-is a fork of the File_CSV class of PEAR's File package.
- </description>
- <lead>
- <name>Jan Schneider</name>
- <user>jan</user>
- <email>jan@horde.org</email>
- <active>yes</active>
- </lead>
- <date>2006-05-08</date>
- <time>21:32:31</time>
- <version>
- <release>0.1.1</release>
- <api>0.1.1</api>
- </version>
- <stability>
- <release>beta</release>
- <api>beta</api>
- </stability>
- <license uri="http://www.php.net/license">PHP</license>
- <notes>
-* Converted to package.xml 2.0 for pear.horde.org
-* Close Horde bug #6372 (ritaselsky@gmail.com)
- </notes>
- <contents>
- <dir name="/">
- <dir name="tests">
- <file name="bug_3839.csv" role="test" />
- <file name="bug_3839.phpt" role="test" />
- <file name="columns.phpt" role="test" />
- <file name="columns1.csv" role="test" />
- <file name="common.php" role="test" />
- <file name="multiline.phpt" role="test" />
- <file name="multiline1.csv" role="test" />
- <file name="notrailing_crlf.csv" role="test" />
- <file name="notrailing_lf.csv" role="test" />
- <file name="quote1.csv" role="test" />
- <file name="quote2.csv" role="test" />
- <file name="quote3.csv" role="test" />
- <file name="quote4.csv" role="test" />
- <file name="quote5.csv" role="test" />
- <file name="quotes.phpt" role="test" />
- <file name="simple_cr.csv" role="test" />
- <file name="simple_crlf.csv" role="test" />
- <file name="simple_lf.csv" role="test" />
- </dir> <!-- //tests -->
- <file baseinstalldir="/File" name="CSV.php" role="php" />
- </dir> <!-- / -->
- </contents>
- <dependencies>
- <required>
- <php>
- <min>4.3.0</min>
- </php>
- <pearinstaller>
- <min>1.4.0b1</min>
- </pearinstaller>
- <package>
- <name>PEAR</name>
- <channel>pear.php.net</channel>
- </package>
- <extension>
- <name>pcre</name>
- </extension>
- </required>
- </dependencies>
- <phprelease />
- <changelog>
- <release>
- <version>
- <release>0.1.0</release>
- <api>0.1.0</api>
- </version>
- <stability>
- <release>beta</release>
- <api>beta</api>
- </stability>
- <date>2004-01-01</date>
- <license uri="http://www.php.net/license">PHP</license>
- <notes>First release.
- </notes>
- </release>
- </changelog>
-</package>
+++ /dev/null
-"Field 1-1", "Field 1-2", "Field 1-3", "Field 1-4"
-"Field 2-1", "Field 2-2", "Field 2-3"
-"Field 3-1", "Field 3-2"
-"Field 4-1"
+++ /dev/null
---TEST--
-File_CSV Test Case 001: Fields count less than expected
---FILE--
-<?php
-/**
- * Test for:
- * - File_CSV::discoverFormat()
- * - File_CSV::readQuoted()
- */
-
-require_once dirname(__FILE__) . '/../CSV.php';
-
-$file = dirname(__FILE__) . '/001.csv';
-$conf = File_CSV::discoverFormat($file);
-$conf['fields'] = 4;
-
-var_dump($conf);
-
-$data = array();
-while ($res = File_CSV::readQuoted($file, $conf)) {
- $data[] = $res;
-}
-
-var_dump($data);
-
-?>
---EXPECT--
-array(4) {
- ["crlf"]=>
- string(1) "
-"
- ["fields"]=>
- int(4)
- ["sep"]=>
- string(1) ","
- ["quote"]=>
- string(1) """
-}
-array(4) {
- [0]=>
- array(4) {
- [0]=>
- string(9) "Field 1-1"
- [1]=>
- string(9) "Field 1-2"
- [2]=>
- string(9) "Field 1-3"
- [3]=>
- string(9) "Field 1-4"
- }
- [1]=>
- array(4) {
- [0]=>
- string(9) "Field 2-1"
- [1]=>
- string(9) "Field 2-2"
- [2]=>
- string(9) "Field 2-3"
- [3]=>
- string(0) ""
- }
- [2]=>
- array(4) {
- [0]=>
- string(9) "Field 3-1"
- [1]=>
- string(9) "Field 3-2"
- [2]=>
- string(0) ""
- [3]=>
- string(0) ""
- }
- [3]=>
- array(4) {
- [0]=>
- string(9) "Field 4-1"
- [1]=>
- string(0) ""
- [2]=>
- string(0) ""
- [3]=>
- string(0) ""
- }
-}
+++ /dev/null
-"Field 1-1", "Field 1-2", "Field 1-3", "Field 1-4"
-"Field 2-1", "Field 2-2", "Field 2-3", "Field 2-4", "Extra Field"
-"Field 3-1", "Field 3-2"
-"Field 4-1"
+++ /dev/null
---TEST--
-File_CSV Test Case 002: Fields count more than expected
---FILE--
-<?php
-/**
- * Test for:
- * - File_CSV::discoverFormat()
- * - File_CSV::readQuoted()
- */
-
-require_once dirname(__FILE__) . '/../CSV.php';
-
-$file = dirname(__FILE__) . '/002.csv';
-$conf = File_CSV::discoverFormat($file);
-$conf['fields'] = 4;
-
-var_dump($conf);
-
-$data = array();
-while ($res = File_CSV::readQuoted($file, $conf)) {
- $data[] = $res;
-}
-
-var_dump($data);
-
-?>
---EXPECT--
-array(4) {
- ["crlf"]=>
- string(1) "
-"
- ["fields"]=>
- int(4)
- ["sep"]=>
- string(1) ","
- ["quote"]=>
- string(1) """
-}
-array(4) {
- [0]=>
- array(4) {
- [0]=>
- string(9) "Field 1-1"
- [1]=>
- string(9) "Field 1-2"
- [2]=>
- string(9) "Field 1-3"
- [3]=>
- string(9) "Field 1-4"
- }
- [1]=>
- array(4) {
- [0]=>
- string(9) "Field 2-1"
- [1]=>
- string(9) "Field 2-2"
- [2]=>
- string(9) "Field 2-3"
- [3]=>
- string(9) "Field 2-4"
- }
- [2]=>
- array(4) {
- [0]=>
- string(9) "Field 3-1"
- [1]=>
- string(9) "Field 3-2"
- [2]=>
- string(0) ""
- [3]=>
- string(0) ""
- }
- [3]=>
- array(4) {
- [0]=>
- string(9) "Field 4-1"
- [1]=>
- string(0) ""
- [2]=>
- string(0) ""
- [3]=>
- string(0) ""
- }
-}
+++ /dev/null
-"Field 1-1","Field 1-2","Field 1-3","Field 1-4"
-"Field 2-1","Field 2-2","Field 2-3","I'm multiline
-Field"
-"Field 3-1","Field 3-2","Field 3-3"
+++ /dev/null
---TEST--
-File_CSV Test Case 003: Windows EOL
---FILE--
-<?php
-/**
- * Test for:
- * - File_CSV::discoverFormat()
- * - File_CSV::readQuoted()
- */
-
-require_once dirname(__FILE__) . '/../CSV.php';
-
-$file = dirname(__FILE__) . '/003.csv';
-$conf = File_CSV::discoverFormat($file);
-
-print "Format:\n";
-print_r($conf);
-print "\n";
-
-$data = array();
-while ($res = File_CSV::readQuoted($file, $conf)) {
- $data[] = $res;
-}
-
-print "Data:\n";
-print_r($data);
-?>
---EXPECT--
-Format:
-Array
-(
- [crlf] =>
-
- [fields] => 4
- [sep] => ,
- [quote] => "
-)
-
-Data:
-Array
-(
- [0] => Array
- (
- [0] => Field 1-1
- [1] => Field 1-2
- [2] => Field 1-3
- [3] => Field 1-4
- )
-
- [1] => Array
- (
- [0] => Field 2-1
- [1] => Field 2-2
- [2] => Field 2-3
- [3] => I'm multiline
-Field
- )
-
- [2] => Array
- (
- [0] => Field 3-1
- [1] => Field 3-2
- [2] => Field 3-3
- [3] =>
- )
-
-)
+++ /dev/null
-"Field 1-1","Field 1-2","Field 1-3","Field 1-4"
-"Field 2-1","Field 2-2","Field 2-3","I'm multiline
-Field"
-"Field 3-1","Field 3-2","Field 3-3"
+++ /dev/null
---TEST--
-File_CSV Test Case 004: Unix EOL
---FILE--
-<?php
-/**
- * Test for:
- * - File_CSV::discoverFormat()
- * - File_CSV::readQuoted()
- */
-
-require_once dirname(__FILE__) . '/../CSV.php';
-
-$file = dirname(__FILE__) . '/004.csv';
-$conf = File_CSV::discoverFormat($file);
-
-print "Format:\n";
-print_r($conf);
-print "\n";
-
-$data = array();
-while ($res = File_CSV::readQuoted($file, $conf)) {
- $data[] = $res;
-}
-
-print "Data:\n";
-print_r($data);
-?>
---EXPECT--
-Format:
-Array
-(
- [crlf] =>
-
- [fields] => 4
- [sep] => ,
- [quote] => "
-)
-
-Data:
-Array
-(
- [0] => Array
- (
- [0] => Field 1-1
- [1] => Field 1-2
- [2] => Field 1-3
- [3] => Field 1-4
- )
-
- [1] => Array
- (
- [0] => Field 2-1
- [1] => Field 2-2
- [2] => Field 2-3
- [3] => I'm multiline
-Field
- )
-
- [2] => Array
- (
- [0] => Field 3-1
- [1] => Field 3-2
- [2] => Field 3-3
- [3] =>
- )
-
-)
+++ /dev/null
-"Field 1-1","Field 1-2","Field 1-3","Field 1-4"\r"Field 2-1","Field 2-2","Field 2-3","I'm multiline\rField"\r"Field 3-1","Field 3-2","Field 3-3"\r
\ No newline at end of file
+++ /dev/null
---TEST--
-File_CSV Test Case 005: Mac EOL
---FILE--
-<?php
-/**
- * Test for:
- * - File_CSV::discoverFormat()
- * - File_CSV::readQuoted()
- */
-
-require_once dirname(__FILE__) . '/../CSV.php';
-
-$file = dirname(__FILE__) . '/005.csv';
-$conf = File_CSV::discoverFormat($file);
-//$conf['fields'] = 4;
-
-print "Format:\n";
-print_r($conf);
-print "\n";
-
-$data = array();
-while ($res = File_CSV::readQuoted($file, $conf)) {
- $data[] = $res;
-}
-
-print "Data:\n";
-print_r($data);
-?>
---EXPECT--
-Format:
-Array
-(
- [crlf] =>
- [fields] => 4
- [sep] => ,
- [quote] => "
-)
-
-Data:
-Array
-(
- [0] => Array
- (
- [0] => Field 1-1
- [1] => Field 1-2
- [2] => Field 1-3
- [3] => Field 1-4
- )
-
- [1] => Array
- (
- [0] => Field 2-1
- [1] => Field 2-2
- [2] => Field 2-3
- [3] => I'm multiline
-Field
- )
-
- [2] => Array
- (
- [0] => Field 3-1
- [1] => Field 3-2
- [2] => Field 3-3
- [3] =>
- )
-
-)
+++ /dev/null
-Subject~Start Date~Start Time~End Date~End Time~All day event~Reminder on/off~Reminder Date~Reminder Time~Category~Description~Priority
-"Inservice on new resource: ""CPNP Toolkit"""~2004-11-08~10:30 AM~2004-11-08~11:30 AM~FALSE~FALSE~~~Training~"CPN Program ...
-Inservice on new resource: ""CPNP Toolkit""
-
-<b>Registration Deadline: October 27, 2004, noon</b>
-
-<a href=""F041108A-Eval.pdf"" target=""_blank"">
-<img src=""acrobat.gif"" border=""0""></a> <a href=""F041108A-Eval.pdf"" target=""_blank""> Session Evaluation - Eligibility for Prize!</a>
-
-<a href=""F041108A-DI.pdf"" target=""_blank"">
-<img src=""acrobat.gif"" border=""0""></a> <a href=""F041108A-DI.pdf"" target=""_blank""> Dial In Numbers for Sites Registered</a>
-
-<a href=""F041108A.pdf"" target=""_blank"">
-<img src=""acrobat.gif"" border=""0""></a> <a href=""F041108A.pdf"" target=""_blank""> Poster and Registration Form</a>
-
-Facilitator: Manager
-
-preblurb preblurb preblurb preblurb preblurb preblurb preblurb preblurb preblurb ""CPNP Toolkit"". postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb .
-
-postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb
-
-Come check out the new resource!"~Normal
+++ /dev/null
---TEST--
-File_CSV: test for Bug #3839
---FILE--
-<?php
-
-require_once dirname(__FILE__) . '/../CSV.php';
-
-$file = dirname(__FILE__) . '/bug_3839.csv';
-
-// Explicit conf since we can't detect these settings. Might be able
-// to improve auto-detection, but it definitely should work with the
-// settings specified explicitly.
-// var_dump(File_CSV::discoverFormat($file));
-$conf['crlf'] = "\r\n";
-$conf['sep'] = '~';
-$conf['fields'] = 12;
-$conf['quote'] = '"';
-
-$csv = array();
-while ($row = File_CSV::read($file, $conf)) {
- if (is_a($row, 'PEAR_Error')) {
- var_dump($row);
- return;
- }
- $csv[] = $row;
-}
-var_dump($csv);
-$warnings = File_CSV::warning();
-if (count($warnings)) {
- var_dump($warnings);
-}
-
-?>
---EXPECT--
-array(2) {
- [0]=>
- array(12) {
- [0]=>
- string(7) "Subject"
- [1]=>
- string(10) "Start Date"
- [2]=>
- string(10) "Start Time"
- [3]=>
- string(8) "End Date"
- [4]=>
- string(8) "End Time"
- [5]=>
- string(13) "All day event"
- [6]=>
- string(15) "Reminder on/off"
- [7]=>
- string(13) "Reminder Date"
- [8]=>
- string(13) "Reminder Time"
- [9]=>
- string(8) "Category"
- [10]=>
- string(11) "Description"
- [11]=>
- string(8) "Priority"
- }
- [1]=>
- array(12) {
- [0]=>
- string(41) "Inservice on new resource: "CPNP Toolkit""
- [1]=>
- string(10) "2004-11-08"
- [2]=>
- string(8) "10:30 AM"
- [3]=>
- string(10) "2004-11-08"
- [4]=>
- string(8) "11:30 AM"
- [5]=>
- string(5) "FALSE"
- [6]=>
- string(5) "FALSE"
- [7]=>
- string(0) ""
- [8]=>
- string(0) ""
- [9]=>
- string(8) "Training"
- [10]=>
- string(1109) "CPN Program ...
-Inservice on new resource: "CPNP Toolkit"
-
-<b>Registration Deadline: October 27, 2004, noon</b>
-
-<a href="F041108A-Eval.pdf" target="_blank">
-<img src="acrobat.gif" border="0"></a> <a href="F041108A-Eval.pdf" target="_blank"> Session Evaluation - Eligibility for Prize!</a>
-
-<a href="F041108A-DI.pdf" target="_blank">
-<img src="acrobat.gif" border="0"></a> <a href="F041108A-DI.pdf" target="_blank"> Dial In Numbers for Sites Registered</a>
-
-<a href="F041108A.pdf" target="_blank">
-<img src="acrobat.gif" border="0"></a> <a href="F041108A.pdf" target="_blank"> Poster and Registration Form</a>
-
-Facilitator: Manager
-
-preblurb preblurb preblurb preblurb preblurb preblurb preblurb preblurb preblurb "CPNP Toolkit". postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb .
-
-postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb
-
-Come check out the new resource!"
- [11]=>
- string(6) "Normal"
- }
-}
+++ /dev/null
-"Betreff","Beginnt am","Beginnt um","Endet am","Endet um","Ganztägiges Ereignis","Erinnerung Ein/Aus","Erinnerung am","Erinnerung um","Besprechungsplanung","Erforderliche Teilnehmer","Optionale Teilnehmer","Besprechungsressourcen","Abrechnungsinformationen","Beschreibung","Kategorien","Ort","Priorität","Privat","Reisekilometer","Vertraulichkeit","Zeitspanne zeigen als"
-"Burger Download Session","2.5.2006","11:50:00","2.5.2006","13:00:00","Aus","Ein","2.5.2006","11:35:00","Haas, Jörg","Kuhl, Oliver",,,,"
-",,"Burger Upload Station (Burger King)","Normal","Aus",,"Normal","1"
+++ /dev/null
---TEST--
-File_CSV: test for Bug #4025
---FILE--
-<?php
-
-require_once dirname(__FILE__) . '/../CSV.php';
-
-$file = dirname(__FILE__) . '/bug_4025.csv';
-
-// Explicit conf since we can't detect these settings. Might be able
-// to improve auto-detection, but it definitely should work with the
-// settings specified explicitly.
-// var_dump(File_CSV::discoverFormat($file));
-$conf['crlf'] = "\r\n";
-$conf['sep'] = ',';
-$conf['fields'] = 22;
-$conf['quote'] = '"';
-
-$csv = array();
-while ($row = File_CSV::read($file, $conf)) {
- if (is_a($row, 'PEAR_Error')) {
- var_dump($row);
- return;
- }
- $csv[] = $row;
-}
-var_dump($csv);
-$warnings = File_CSV::warning();
-if (count($warnings)) {
- var_dump($warnings);
-}
-
-?>
---EXPECT--
-array(2) {
- [0]=>
- array(22) {
- [0]=>
- string(7) "Betreff"
- [1]=>
- string(10) "Beginnt am"
- [2]=>
- string(10) "Beginnt um"
- [3]=>
- string(8) "Endet am"
- [4]=>
- string(8) "Endet um"
- [5]=>
- string(20) "Ganztägiges Ereignis"
- [6]=>
- string(18) "Erinnerung Ein/Aus"
- [7]=>
- string(13) "Erinnerung am"
- [8]=>
- string(13) "Erinnerung um"
- [9]=>
- string(19) "Besprechungsplanung"
- [10]=>
- string(24) "Erforderliche Teilnehmer"
- [11]=>
- string(20) "Optionale Teilnehmer"
- [12]=>
- string(22) "Besprechungsressourcen"
- [13]=>
- string(24) "Abrechnungsinformationen"
- [14]=>
- string(12) "Beschreibung"
- [15]=>
- string(10) "Kategorien"
- [16]=>
- string(3) "Ort"
- [17]=>
- string(9) "Priorität"
- [18]=>
- string(6) "Privat"
- [19]=>
- string(14) "Reisekilometer"
- [20]=>
- string(15) "Vertraulichkeit"
- [21]=>
- string(21) "Zeitspanne zeigen als"
- }
- [1]=>
- array(22) {
- [0]=>
- string(23) "Burger Download Session"
- [1]=>
- string(8) "2.5.2006"
- [2]=>
- string(8) "11:50:00"
- [3]=>
- string(8) "2.5.2006"
- [4]=>
- string(8) "13:00:00"
- [5]=>
- string(3) "Aus"
- [6]=>
- string(3) "Ein"
- [7]=>
- string(8) "2.5.2006"
- [8]=>
- string(8) "11:35:00"
- [9]=>
- string(10) "Haas, Jörg"
- [10]=>
- string(12) "Kuhl, Oliver"
- [11]=>
- string(0) ""
- [12]=>
- string(0) ""
- [13]=>
- string(0) ""
- [14]=>
- string(1) "
-"
- [15]=>
- string(0) ""
- [16]=>
- string(35) "Burger Upload Station (Burger King)"
- [17]=>
- string(6) "Normal"
- [18]=>
- string(3) "Aus"
- [19]=>
- string(0) ""
- [20]=>
- string(6) "Normal"
- [21]=>
- string(1) "1"
- }
-}
+++ /dev/null
-"Title","First Name","Middle Name","Last Name","Suffix","Company","Department","Job Title","Business Street","Business Street 2","Business Street 3","Business City","Business State","Business Postal Code","Business Country/Region","Home Street","Home Street 2","Home Street 3","Home City","Home State","Home Postal Code","Home Country/Region","Other Street","Other Street 2","Other Street 3","Other City","Other State","Other Postal Code","Other Country/Region","Assistant's Phone","Business Fax","Business Phone","Business Phone 2","Callback","Car Phone","Company Main Phone","Home Fax","Home Phone","Home Phone 2","ISDN","Mobile Phone","Other Fax","Other Phone","Pager","Primary Phone","Radio Phone","TTY/TDD Phone","Telex","Account","Anniversary","Assistant's Name","Billing Information","Birthday","Business Address PO Box","Categories","Children","Directory Server","E-mail Address","E-mail Type","E-mail Display Name","E-mail 2 Address","E-mail 2 Type","E-mail 2 Display Name","E-mail 3 Address","E-mail 3 Type","E-mail 3 Display Name","Gender","Government ID Number","Hobby","Home Address PO Box","Initials","Internet Free Busy","Keywords","Language","Location","Manager's Name","Mileage","Notes","Office Location","Organizational ID Number","Other Address PO Box","Priority","Private","Profession","Referred By","Sensitivity","Spouse","User 1","User 2","User 3","User 4","Web Page"
-"","John","","Smith","","International Inc","","","",,,"","","","","",,,"","","","","",,,"","","","","","(123) 555-1111","(123) 555-2222","","","","","","","","","(123) 555-3333","","","","","","","","","0/0/00","",,"0/0/00",,"Programming",,,"john@example.com","SMTP","John Smith (john@example.com)",,,,,,,"Unspecified","",,,"J.S.","","","","","",,"PHP
-Perl
-Python
-","","",,"Normal","False","",,"Normal","","","","","",""
+++ /dev/null
---TEST--
-File_CSV: test for Bug #6311
---FILE--
-<?php
-
-require_once dirname(__FILE__) . '/../CSV.php';
-
-$file = dirname(__FILE__) . '/bug_6311.csv';
-
-// Explicit conf since we can't detect these settings. Might be able
-// to improve auto-detection, but it definitely should work with the
-// settings specified explicitly.
-// var_dump(File_CSV::discoverFormat($file));
-$conf['crlf'] = "\n";
-$conf['sep'] = ',';
-$conf['fields'] = 92;
-$conf['quote'] = '"';
-
-$csv = array();
-while ($row = File_CSV::read($file, $conf)) {
- if (is_a($row, 'PEAR_Error')) {
- var_dump($row);
- exit;
- }
- $csv[] = $row;
-}
-var_dump($csv);
-$warnings = File_CSV::warning();
-if (count($warnings)) {
- var_dump($warnings);
-}
-
-?>
---EXPECT--
-array(2) {
- [0]=>
- array(92) {
- [0]=>
- string(5) "Title"
- [1]=>
- string(10) "First Name"
- [2]=>
- string(11) "Middle Name"
- [3]=>
- string(9) "Last Name"
- [4]=>
- string(6) "Suffix"
- [5]=>
- string(7) "Company"
- [6]=>
- string(10) "Department"
- [7]=>
- string(9) "Job Title"
- [8]=>
- string(15) "Business Street"
- [9]=>
- string(17) "Business Street 2"
- [10]=>
- string(17) "Business Street 3"
- [11]=>
- string(13) "Business City"
- [12]=>
- string(14) "Business State"
- [13]=>
- string(20) "Business Postal Code"
- [14]=>
- string(23) "Business Country/Region"
- [15]=>
- string(11) "Home Street"
- [16]=>
- string(13) "Home Street 2"
- [17]=>
- string(13) "Home Street 3"
- [18]=>
- string(9) "Home City"
- [19]=>
- string(10) "Home State"
- [20]=>
- string(16) "Home Postal Code"
- [21]=>
- string(19) "Home Country/Region"
- [22]=>
- string(12) "Other Street"
- [23]=>
- string(14) "Other Street 2"
- [24]=>
- string(14) "Other Street 3"
- [25]=>
- string(10) "Other City"
- [26]=>
- string(11) "Other State"
- [27]=>
- string(17) "Other Postal Code"
- [28]=>
- string(20) "Other Country/Region"
- [29]=>
- string(17) "Assistant's Phone"
- [30]=>
- string(12) "Business Fax"
- [31]=>
- string(14) "Business Phone"
- [32]=>
- string(16) "Business Phone 2"
- [33]=>
- string(8) "Callback"
- [34]=>
- string(9) "Car Phone"
- [35]=>
- string(18) "Company Main Phone"
- [36]=>
- string(8) "Home Fax"
- [37]=>
- string(10) "Home Phone"
- [38]=>
- string(12) "Home Phone 2"
- [39]=>
- string(4) "ISDN"
- [40]=>
- string(12) "Mobile Phone"
- [41]=>
- string(9) "Other Fax"
- [42]=>
- string(11) "Other Phone"
- [43]=>
- string(5) "Pager"
- [44]=>
- string(13) "Primary Phone"
- [45]=>
- string(11) "Radio Phone"
- [46]=>
- string(13) "TTY/TDD Phone"
- [47]=>
- string(5) "Telex"
- [48]=>
- string(7) "Account"
- [49]=>
- string(11) "Anniversary"
- [50]=>
- string(16) "Assistant's Name"
- [51]=>
- string(19) "Billing Information"
- [52]=>
- string(8) "Birthday"
- [53]=>
- string(23) "Business Address PO Box"
- [54]=>
- string(10) "Categories"
- [55]=>
- string(8) "Children"
- [56]=>
- string(16) "Directory Server"
- [57]=>
- string(14) "E-mail Address"
- [58]=>
- string(11) "E-mail Type"
- [59]=>
- string(19) "E-mail Display Name"
- [60]=>
- string(16) "E-mail 2 Address"
- [61]=>
- string(13) "E-mail 2 Type"
- [62]=>
- string(21) "E-mail 2 Display Name"
- [63]=>
- string(16) "E-mail 3 Address"
- [64]=>
- string(13) "E-mail 3 Type"
- [65]=>
- string(21) "E-mail 3 Display Name"
- [66]=>
- string(6) "Gender"
- [67]=>
- string(20) "Government ID Number"
- [68]=>
- string(5) "Hobby"
- [69]=>
- string(19) "Home Address PO Box"
- [70]=>
- string(8) "Initials"
- [71]=>
- string(18) "Internet Free Busy"
- [72]=>
- string(8) "Keywords"
- [73]=>
- string(8) "Language"
- [74]=>
- string(8) "Location"
- [75]=>
- string(14) "Manager's Name"
- [76]=>
- string(7) "Mileage"
- [77]=>
- string(5) "Notes"
- [78]=>
- string(15) "Office Location"
- [79]=>
- string(24) "Organizational ID Number"
- [80]=>
- string(20) "Other Address PO Box"
- [81]=>
- string(8) "Priority"
- [82]=>
- string(7) "Private"
- [83]=>
- string(10) "Profession"
- [84]=>
- string(11) "Referred By"
- [85]=>
- string(11) "Sensitivity"
- [86]=>
- string(6) "Spouse"
- [87]=>
- string(6) "User 1"
- [88]=>
- string(6) "User 2"
- [89]=>
- string(6) "User 3"
- [90]=>
- string(6) "User 4"
- [91]=>
- string(8) "Web Page"
- }
- [1]=>
- array(92) {
- [0]=>
- string(0) ""
- [1]=>
- string(4) "John"
- [2]=>
- string(0) ""
- [3]=>
- string(5) "Smith"
- [4]=>
- string(0) ""
- [5]=>
- string(17) "International Inc"
- [6]=>
- string(0) ""
- [7]=>
- string(0) ""
- [8]=>
- string(0) ""
- [9]=>
- string(0) ""
- [10]=>
- string(0) ""
- [11]=>
- string(0) ""
- [12]=>
- string(0) ""
- [13]=>
- string(0) ""
- [14]=>
- string(0) ""
- [15]=>
- string(0) ""
- [16]=>
- string(0) ""
- [17]=>
- string(0) ""
- [18]=>
- string(0) ""
- [19]=>
- string(0) ""
- [20]=>
- string(0) ""
- [21]=>
- string(0) ""
- [22]=>
- string(0) ""
- [23]=>
- string(0) ""
- [24]=>
- string(0) ""
- [25]=>
- string(0) ""
- [26]=>
- string(0) ""
- [27]=>
- string(0) ""
- [28]=>
- string(0) ""
- [29]=>
- string(0) ""
- [30]=>
- string(14) "(123) 555-1111"
- [31]=>
- string(14) "(123) 555-2222"
- [32]=>
- string(0) ""
- [33]=>
- string(0) ""
- [34]=>
- string(0) ""
- [35]=>
- string(0) ""
- [36]=>
- string(0) ""
- [37]=>
- string(0) ""
- [38]=>
- string(0) ""
- [39]=>
- string(0) ""
- [40]=>
- string(14) "(123) 555-3333"
- [41]=>
- string(0) ""
- [42]=>
- string(0) ""
- [43]=>
- string(0) ""
- [44]=>
- string(0) ""
- [45]=>
- string(0) ""
- [46]=>
- string(0) ""
- [47]=>
- string(0) ""
- [48]=>
- string(0) ""
- [49]=>
- string(6) "0/0/00"
- [50]=>
- string(0) ""
- [51]=>
- string(0) ""
- [52]=>
- string(6) "0/0/00"
- [53]=>
- string(0) ""
- [54]=>
- string(11) "Programming"
- [55]=>
- string(0) ""
- [56]=>
- string(0) ""
- [57]=>
- string(16) "john@example.com"
- [58]=>
- string(4) "SMTP"
- [59]=>
- string(29) "John Smith (john@example.com)"
- [60]=>
- string(0) ""
- [61]=>
- string(0) ""
- [62]=>
- string(0) ""
- [63]=>
- string(0) ""
- [64]=>
- string(0) ""
- [65]=>
- string(0) ""
- [66]=>
- string(11) "Unspecified"
- [67]=>
- string(0) ""
- [68]=>
- string(0) ""
- [69]=>
- string(0) ""
- [70]=>
- string(4) "J.S."
- [71]=>
- string(0) ""
- [72]=>
- string(0) ""
- [73]=>
- string(0) ""
- [74]=>
- string(0) ""
- [75]=>
- string(0) ""
- [76]=>
- string(0) ""
- [77]=>
- string(16) "PHP
-Perl
-Python
-"
- [78]=>
- string(0) ""
- [79]=>
- string(0) ""
- [80]=>
- string(0) ""
- [81]=>
- string(6) "Normal"
- [82]=>
- string(5) "False"
- [83]=>
- string(0) ""
- [84]=>
- string(0) ""
- [85]=>
- string(6) "Normal"
- [86]=>
- string(0) ""
- [87]=>
- string(0) ""
- [88]=>
- string(0) ""
- [89]=>
- string(0) ""
- [90]=>
- string(0) ""
- [91]=>
- string(0) ""
- }
-}
+++ /dev/null
-"Title","First Name","Middle Name","Last Name","Suffix","Company","Department","Job Title","Business Street","Business Street 2","Business Street 3","Business City","Business State","Business Postal Code","Business Country/Region","Home Street","Home Street 2","Home Street 3","Home City","Home State","Home Postal Code","Home Country/Region","Other Street","Other Street 2","Other Street 3","Other City","Other State","Other Postal Code","Other Country/Region","Assistant's Phone","Business Fax","Business Phone","Business Phone 2","Callback","Car Phone","Company Main Phone","Home Fax","Home Phone","Home Phone 2","ISDN","Mobile Phone","Other Fax","Other Phone","Pager","Primary Phone","Radio Phone","TTY/TDD Phone","Telex","Account","Anniversary","Assistant's Name","Billing Information","Birthday","Business Address PO Box","Categories","Children","Directory Server","E-mail Address","E-mail Type","E-mail Display Name","E-mail 2 Address","E-mail 2 Type","E-mail 2 Display Name","E-mail 3 Address","E-mail 3 Type","E-mail 3 Display Name","Gender","Government ID Number","Hobby","Home Address PO Box","Initials","Internet Free Busy","Keywords","Language","Location","Manager's Name","Mileage","Notes","Office Location","Organizational ID Number","Other Address PO Box","Priority","Private","Profession","Referred By","Sensitivity","Spouse","User 1","User 2","User 3","User 4","Web Page"
-"","","","","","","","","Big Tower'"", 1"" Floor
-123 Main Street",,,"","","","","",,,"","","","","",,,"","","","","","","","","","","","","","","","","","","","","","","","","0/0/00","",,"0/0/00",,,,,"","","",,,,,,,"Unspecified","",,,"","","","","","",,,"","",,"Normal","False","",,"Normal","","","","","",""
+++ /dev/null
---TEST--
-File_CSV: test for Bug #6370
---FILE--
-<?php
-
-require_once dirname(__FILE__) . '/../CSV.php';
-
-$file = dirname(__FILE__) . '/bug_6370.csv';
-
-// Explicit conf since we can't detect these settings. Might be able
-// to improve auto-detection, but it definitely should work with the
-// settings specified explicitly.
-// var_dump(File_CSV::discoverFormat($file));
-$conf['crlf'] = "\n";
-$conf['sep'] = ',';
-$conf['fields'] = 92;
-$conf['quote'] = '"';
-
-$csv = array();
-while ($row = File_CSV::read($file, $conf)) {
- if (is_a($row, 'PEAR_Error')) {
- var_dump($row);
- exit;
- }
- $csv[] = $row;
-}
-var_dump($csv);
-$warnings = File_CSV::warning();
-if (count($warnings)) {
- var_dump($warnings);
-}
-
-?>
---EXPECT--
-array(2) {
- [0]=>
- array(92) {
- [0]=>
- string(5) "Title"
- [1]=>
- string(10) "First Name"
- [2]=>
- string(11) "Middle Name"
- [3]=>
- string(9) "Last Name"
- [4]=>
- string(6) "Suffix"
- [5]=>
- string(7) "Company"
- [6]=>
- string(10) "Department"
- [7]=>
- string(9) "Job Title"
- [8]=>
- string(15) "Business Street"
- [9]=>
- string(17) "Business Street 2"
- [10]=>
- string(17) "Business Street 3"
- [11]=>
- string(13) "Business City"
- [12]=>
- string(14) "Business State"
- [13]=>
- string(20) "Business Postal Code"
- [14]=>
- string(23) "Business Country/Region"
- [15]=>
- string(11) "Home Street"
- [16]=>
- string(13) "Home Street 2"
- [17]=>
- string(13) "Home Street 3"
- [18]=>
- string(9) "Home City"
- [19]=>
- string(10) "Home State"
- [20]=>
- string(16) "Home Postal Code"
- [21]=>
- string(19) "Home Country/Region"
- [22]=>
- string(12) "Other Street"
- [23]=>
- string(14) "Other Street 2"
- [24]=>
- string(14) "Other Street 3"
- [25]=>
- string(10) "Other City"
- [26]=>
- string(11) "Other State"
- [27]=>
- string(17) "Other Postal Code"
- [28]=>
- string(20) "Other Country/Region"
- [29]=>
- string(17) "Assistant's Phone"
- [30]=>
- string(12) "Business Fax"
- [31]=>
- string(14) "Business Phone"
- [32]=>
- string(16) "Business Phone 2"
- [33]=>
- string(8) "Callback"
- [34]=>
- string(9) "Car Phone"
- [35]=>
- string(18) "Company Main Phone"
- [36]=>
- string(8) "Home Fax"
- [37]=>
- string(10) "Home Phone"
- [38]=>
- string(12) "Home Phone 2"
- [39]=>
- string(4) "ISDN"
- [40]=>
- string(12) "Mobile Phone"
- [41]=>
- string(9) "Other Fax"
- [42]=>
- string(11) "Other Phone"
- [43]=>
- string(5) "Pager"
- [44]=>
- string(13) "Primary Phone"
- [45]=>
- string(11) "Radio Phone"
- [46]=>
- string(13) "TTY/TDD Phone"
- [47]=>
- string(5) "Telex"
- [48]=>
- string(7) "Account"
- [49]=>
- string(11) "Anniversary"
- [50]=>
- string(16) "Assistant's Name"
- [51]=>
- string(19) "Billing Information"
- [52]=>
- string(8) "Birthday"
- [53]=>
- string(23) "Business Address PO Box"
- [54]=>
- string(10) "Categories"
- [55]=>
- string(8) "Children"
- [56]=>
- string(16) "Directory Server"
- [57]=>
- string(14) "E-mail Address"
- [58]=>
- string(11) "E-mail Type"
- [59]=>
- string(19) "E-mail Display Name"
- [60]=>
- string(16) "E-mail 2 Address"
- [61]=>
- string(13) "E-mail 2 Type"
- [62]=>
- string(21) "E-mail 2 Display Name"
- [63]=>
- string(16) "E-mail 3 Address"
- [64]=>
- string(13) "E-mail 3 Type"
- [65]=>
- string(21) "E-mail 3 Display Name"
- [66]=>
- string(6) "Gender"
- [67]=>
- string(20) "Government ID Number"
- [68]=>
- string(5) "Hobby"
- [69]=>
- string(19) "Home Address PO Box"
- [70]=>
- string(8) "Initials"
- [71]=>
- string(18) "Internet Free Busy"
- [72]=>
- string(8) "Keywords"
- [73]=>
- string(8) "Language"
- [74]=>
- string(8) "Location"
- [75]=>
- string(14) "Manager's Name"
- [76]=>
- string(7) "Mileage"
- [77]=>
- string(5) "Notes"
- [78]=>
- string(15) "Office Location"
- [79]=>
- string(24) "Organizational ID Number"
- [80]=>
- string(20) "Other Address PO Box"
- [81]=>
- string(8) "Priority"
- [82]=>
- string(7) "Private"
- [83]=>
- string(10) "Profession"
- [84]=>
- string(11) "Referred By"
- [85]=>
- string(11) "Sensitivity"
- [86]=>
- string(6) "Spouse"
- [87]=>
- string(6) "User 1"
- [88]=>
- string(6) "User 2"
- [89]=>
- string(6) "User 3"
- [90]=>
- string(6) "User 4"
- [91]=>
- string(8) "Web Page"
- }
- [1]=>
- array(92) {
- [0]=>
- string(0) ""
- [1]=>
- string(0) ""
- [2]=>
- string(0) ""
- [3]=>
- string(0) ""
- [4]=>
- string(0) ""
- [5]=>
- string(0) ""
- [6]=>
- string(0) ""
- [7]=>
- string(0) ""
- [8]=>
- string(37) "Big Tower'", 1" Floor
-123 Main Street"
- [9]=>
- string(0) ""
- [10]=>
- string(0) ""
- [11]=>
- string(0) ""
- [12]=>
- string(0) ""
- [13]=>
- string(0) ""
- [14]=>
- string(0) ""
- [15]=>
- string(0) ""
- [16]=>
- string(0) ""
- [17]=>
- string(0) ""
- [18]=>
- string(0) ""
- [19]=>
- string(0) ""
- [20]=>
- string(0) ""
- [21]=>
- string(0) ""
- [22]=>
- string(0) ""
- [23]=>
- string(0) ""
- [24]=>
- string(0) ""
- [25]=>
- string(0) ""
- [26]=>
- string(0) ""
- [27]=>
- string(0) ""
- [28]=>
- string(0) ""
- [29]=>
- string(0) ""
- [30]=>
- string(0) ""
- [31]=>
- string(0) ""
- [32]=>
- string(0) ""
- [33]=>
- string(0) ""
- [34]=>
- string(0) ""
- [35]=>
- string(0) ""
- [36]=>
- string(0) ""
- [37]=>
- string(0) ""
- [38]=>
- string(0) ""
- [39]=>
- string(0) ""
- [40]=>
- string(0) ""
- [41]=>
- string(0) ""
- [42]=>
- string(0) ""
- [43]=>
- string(0) ""
- [44]=>
- string(0) ""
- [45]=>
- string(0) ""
- [46]=>
- string(0) ""
- [47]=>
- string(0) ""
- [48]=>
- string(0) ""
- [49]=>
- string(6) "0/0/00"
- [50]=>
- string(0) ""
- [51]=>
- string(0) ""
- [52]=>
- string(6) "0/0/00"
- [53]=>
- string(0) ""
- [54]=>
- string(0) ""
- [55]=>
- string(0) ""
- [56]=>
- string(0) ""
- [57]=>
- string(0) ""
- [58]=>
- string(0) ""
- [59]=>
- string(0) ""
- [60]=>
- string(0) ""
- [61]=>
- string(0) ""
- [62]=>
- string(0) ""
- [63]=>
- string(0) ""
- [64]=>
- string(0) ""
- [65]=>
- string(0) ""
- [66]=>
- string(11) "Unspecified"
- [67]=>
- string(0) ""
- [68]=>
- string(0) ""
- [69]=>
- string(0) ""
- [70]=>
- string(0) ""
- [71]=>
- string(0) ""
- [72]=>
- string(0) ""
- [73]=>
- string(0) ""
- [74]=>
- string(0) ""
- [75]=>
- string(0) ""
- [76]=>
- string(0) ""
- [77]=>
- string(1) ""
- [78]=>
- string(0) ""
- [79]=>
- string(0) ""
- [80]=>
- string(0) ""
- [81]=>
- string(6) "Normal"
- [82]=>
- string(5) "False"
- [83]=>
- string(0) ""
- [84]=>
- string(0) ""
- [85]=>
- string(6) "Normal"
- [86]=>
- string(0) ""
- [87]=>
- string(0) ""
- [88]=>
- string(0) ""
- [89]=>
- string(0) ""
- [90]=>
- string(0) ""
- [91]=>
- string(0) ""
- }
-}
+++ /dev/null
-"Title","First Name","Middle Name","Last Name","Suffix","Company","Department","Job Title","Business Street","Business Street 2","Business Street 3","Business City","Business State","Business Postal Code","Business Country/Region","Home Street","Home Street 2","Home Street 3","Home City","Home State","Home Postal Code","Home Country/Region","Other Street","Other Street 2","Other Street 3","Other City","Other State","Other Postal Code","Other Country/Region","Assistant's Phone","Business Fax","Business Phone","Business Phone 2","Callback","Car Phone","Company Main Phone","Home Fax","Home Phone","Home Phone 2","ISDN","Mobile Phone","Other Fax","Other Phone","Pager","Primary Phone","Radio Phone","TTY/TDD Phone","Telex","Account","Anniversary","Assistant's Name","Billing Information","Birthday","Business Address PO Box","Categories","Children","Directory Server","E-mail Address","E-mail Type","E-mail Display Name","E-mail 2 Address","E-mail 2 Type","E-mail 2 Display Name","E-mail 3 Address","E-mail 3 Type","E-mail 3 Display Name","Gender","Government ID Number","Hobby","Home Address PO Box","Initials","Internet Free Busy","Keywords","Language","Location","Manager's Name","Mileage","Notes","Office Location","Organizational ID Number","Other Address PO Box","Priority","Private","Profession","Referred By","Sensitivity","Spouse","User 1","User 2","User 3","User 4","Web Page"
-"","","","","","","","","123, 12th Floor,
-Main Street",,,"","","","","",,,"","","","","",,,"","","","","","","","","","","","","","","","","","","","","","","","","0/0/00","",,"0/0/00",,"",,,"","","","","","",,,,"Unspecified","",,,"","","","","","",,"
-","","",,"Normal","False","",,"Normal","","","","","",""
+++ /dev/null
---TEST--
-File_CSV: test for Bug #6372
---FILE--
-<?php
-
-require_once dirname(__FILE__) . '/../CSV.php';
-
-$file = dirname(__FILE__) . '/bug_6372.csv';
-
-// Explicit conf since we can't detect these settings. Might be able
-// to improve auto-detection, but it definitely should work with the
-// settings specified explicitly.
-// var_dump(File_CSV::discoverFormat($file));
-$conf['crlf'] = "\n";
-$conf['sep'] = ',';
-$conf['fields'] = 92;
-$conf['quote'] = '"';
-
-$csv = array();
-while ($row = File_CSV::read($file, $conf)) {
- if (is_a($row, 'PEAR_Error')) {
- var_dump($row);
- exit;
- }
- $csv[] = $row;
-}
-var_dump($csv);
-$warnings = File_CSV::warning();
-if (count($warnings)) {
- var_dump($warnings);
-}
-
-?>
---EXPECT--
-array(2) {
- [0]=>
- array(92) {
- [0]=>
- string(5) "Title"
- [1]=>
- string(10) "First Name"
- [2]=>
- string(11) "Middle Name"
- [3]=>
- string(9) "Last Name"
- [4]=>
- string(6) "Suffix"
- [5]=>
- string(7) "Company"
- [6]=>
- string(10) "Department"
- [7]=>
- string(9) "Job Title"
- [8]=>
- string(15) "Business Street"
- [9]=>
- string(17) "Business Street 2"
- [10]=>
- string(17) "Business Street 3"
- [11]=>
- string(13) "Business City"
- [12]=>
- string(14) "Business State"
- [13]=>
- string(20) "Business Postal Code"
- [14]=>
- string(23) "Business Country/Region"
- [15]=>
- string(11) "Home Street"
- [16]=>
- string(13) "Home Street 2"
- [17]=>
- string(13) "Home Street 3"
- [18]=>
- string(9) "Home City"
- [19]=>
- string(10) "Home State"
- [20]=>
- string(16) "Home Postal Code"
- [21]=>
- string(19) "Home Country/Region"
- [22]=>
- string(12) "Other Street"
- [23]=>
- string(14) "Other Street 2"
- [24]=>
- string(14) "Other Street 3"
- [25]=>
- string(10) "Other City"
- [26]=>
- string(11) "Other State"
- [27]=>
- string(17) "Other Postal Code"
- [28]=>
- string(20) "Other Country/Region"
- [29]=>
- string(17) "Assistant's Phone"
- [30]=>
- string(12) "Business Fax"
- [31]=>
- string(14) "Business Phone"
- [32]=>
- string(16) "Business Phone 2"
- [33]=>
- string(8) "Callback"
- [34]=>
- string(9) "Car Phone"
- [35]=>
- string(18) "Company Main Phone"
- [36]=>
- string(8) "Home Fax"
- [37]=>
- string(10) "Home Phone"
- [38]=>
- string(12) "Home Phone 2"
- [39]=>
- string(4) "ISDN"
- [40]=>
- string(12) "Mobile Phone"
- [41]=>
- string(9) "Other Fax"
- [42]=>
- string(11) "Other Phone"
- [43]=>
- string(5) "Pager"
- [44]=>
- string(13) "Primary Phone"
- [45]=>
- string(11) "Radio Phone"
- [46]=>
- string(13) "TTY/TDD Phone"
- [47]=>
- string(5) "Telex"
- [48]=>
- string(7) "Account"
- [49]=>
- string(11) "Anniversary"
- [50]=>
- string(16) "Assistant's Name"
- [51]=>
- string(19) "Billing Information"
- [52]=>
- string(8) "Birthday"
- [53]=>
- string(23) "Business Address PO Box"
- [54]=>
- string(10) "Categories"
- [55]=>
- string(8) "Children"
- [56]=>
- string(16) "Directory Server"
- [57]=>
- string(14) "E-mail Address"
- [58]=>
- string(11) "E-mail Type"
- [59]=>
- string(19) "E-mail Display Name"
- [60]=>
- string(16) "E-mail 2 Address"
- [61]=>
- string(13) "E-mail 2 Type"
- [62]=>
- string(21) "E-mail 2 Display Name"
- [63]=>
- string(16) "E-mail 3 Address"
- [64]=>
- string(13) "E-mail 3 Type"
- [65]=>
- string(21) "E-mail 3 Display Name"
- [66]=>
- string(6) "Gender"
- [67]=>
- string(20) "Government ID Number"
- [68]=>
- string(5) "Hobby"
- [69]=>
- string(19) "Home Address PO Box"
- [70]=>
- string(8) "Initials"
- [71]=>
- string(18) "Internet Free Busy"
- [72]=>
- string(8) "Keywords"
- [73]=>
- string(8) "Language"
- [74]=>
- string(8) "Location"
- [75]=>
- string(14) "Manager's Name"
- [76]=>
- string(7) "Mileage"
- [77]=>
- string(5) "Notes"
- [78]=>
- string(15) "Office Location"
- [79]=>
- string(24) "Organizational ID Number"
- [80]=>
- string(20) "Other Address PO Box"
- [81]=>
- string(8) "Priority"
- [82]=>
- string(7) "Private"
- [83]=>
- string(10) "Profession"
- [84]=>
- string(11) "Referred By"
- [85]=>
- string(11) "Sensitivity"
- [86]=>
- string(6) "Spouse"
- [87]=>
- string(6) "User 1"
- [88]=>
- string(6) "User 2"
- [89]=>
- string(6) "User 3"
- [90]=>
- string(6) "User 4"
- [91]=>
- string(8) "Web Page"
- }
- [1]=>
- array(92) {
- [0]=>
- string(0) ""
- [1]=>
- string(0) ""
- [2]=>
- string(0) ""
- [3]=>
- string(0) ""
- [4]=>
- string(0) ""
- [5]=>
- string(0) ""
- [6]=>
- string(0) ""
- [7]=>
- string(0) ""
- [8]=>
- string(28) "123, 12th Floor,
-Main Street"
- [9]=>
- string(0) ""
- [10]=>
- string(0) ""
- [11]=>
- string(0) ""
- [12]=>
- string(0) ""
- [13]=>
- string(0) ""
- [14]=>
- string(0) ""
- [15]=>
- string(0) ""
- [16]=>
- string(0) ""
- [17]=>
- string(0) ""
- [18]=>
- string(0) ""
- [19]=>
- string(0) ""
- [20]=>
- string(0) ""
- [21]=>
- string(0) ""
- [22]=>
- string(0) ""
- [23]=>
- string(0) ""
- [24]=>
- string(0) ""
- [25]=>
- string(0) ""
- [26]=>
- string(0) ""
- [27]=>
- string(0) ""
- [28]=>
- string(0) ""
- [29]=>
- string(0) ""
- [30]=>
- string(0) ""
- [31]=>
- string(0) ""
- [32]=>
- string(0) ""
- [33]=>
- string(0) ""
- [34]=>
- string(0) ""
- [35]=>
- string(0) ""
- [36]=>
- string(0) ""
- [37]=>
- string(0) ""
- [38]=>
- string(0) ""
- [39]=>
- string(0) ""
- [40]=>
- string(0) ""
- [41]=>
- string(0) ""
- [42]=>
- string(0) ""
- [43]=>
- string(0) ""
- [44]=>
- string(0) ""
- [45]=>
- string(0) ""
- [46]=>
- string(0) ""
- [47]=>
- string(0) ""
- [48]=>
- string(0) ""
- [49]=>
- string(6) "0/0/00"
- [50]=>
- string(0) ""
- [51]=>
- string(0) ""
- [52]=>
- string(6) "0/0/00"
- [53]=>
- string(0) ""
- [54]=>
- string(0) ""
- [55]=>
- string(0) ""
- [56]=>
- string(0) ""
- [57]=>
- string(0) ""
- [58]=>
- string(0) ""
- [59]=>
- string(0) ""
- [60]=>
- string(0) ""
- [61]=>
- string(0) ""
- [62]=>
- string(0) ""
- [63]=>
- string(0) ""
- [64]=>
- string(0) ""
- [65]=>
- string(0) ""
- [66]=>
- string(11) "Unspecified"
- [67]=>
- string(0) ""
- [68]=>
- string(0) ""
- [69]=>
- string(0) ""
- [70]=>
- string(0) ""
- [71]=>
- string(0) ""
- [72]=>
- string(0) ""
- [73]=>
- string(0) ""
- [74]=>
- string(0) ""
- [75]=>
- string(0) ""
- [76]=>
- string(0) ""
- [77]=>
- string(1) "
-"
- [78]=>
- string(0) ""
- [79]=>
- string(0) ""
- [80]=>
- string(0) ""
- [81]=>
- string(6) "Normal"
- [82]=>
- string(5) "False"
- [83]=>
- string(0) ""
- [84]=>
- string(0) ""
- [85]=>
- string(6) "Normal"
- [86]=>
- string(0) ""
- [87]=>
- string(0) ""
- [88]=>
- string(0) ""
- [89]=>
- string(0) ""
- [90]=>
- string(0) ""
- [91]=>
- string(0) ""
- }
-}
+++ /dev/null
---TEST--
-File_CSV: column count tests
---FILE--
-<?php
-
-require dirname(__FILE__) . '/common.php';
-test_csv('columns1', 'columns2');
-
-?>
---EXPECT--
-array(4) {
- [0]=>
- array(3) {
- [0]=>
- string(3) "one"
- [1]=>
- string(3) "two"
- [2]=>
- string(5) "three"
- }
- [1]=>
- array(3) {
- [0]=>
- string(4) "four"
- [1]=>
- string(4) "five"
- [2]=>
- string(0) ""
- }
- [2]=>
- array(3) {
- [0]=>
- string(3) "six"
- [1]=>
- string(5) "seven"
- [2]=>
- string(5) "eight"
- }
- [3]=>
- array(3) {
- [0]=>
- string(4) "nine"
- [1]=>
- string(3) "ten"
- [2]=>
- string(6) "eleven"
- }
-}
-array(2) {
- [0]=>
- string(54) "Wrong number of fields in line 2. Expected 3, found 2."
- [1]=>
- string(48) "More fields found in line 4 than the expected 3."
-}
-array(4) {
- [0]=>
- array(3) {
- [0]=>
- string(3) "one"
- [1]=>
- string(3) "two"
- [2]=>
- string(5) "three"
- }
- [1]=>
- array(3) {
- [0]=>
- string(4) "four"
- [1]=>
- string(4) "five"
- [2]=>
- string(0) ""
- }
- [2]=>
- array(3) {
- [0]=>
- string(3) "six"
- [1]=>
- string(5) "seven"
- [2]=>
- string(5) "eight"
- }
- [3]=>
- array(3) {
- [0]=>
- string(4) "nine"
- [1]=>
- string(3) "ten"
- [2]=>
- string(6) "eleven"
- }
-}
-array(2) {
- [0]=>
- string(54) "Wrong number of fields in line 2. Expected 3, found 2."
- [1]=>
- string(48) "More fields found in line 4 than the expected 3."
-}
+++ /dev/null
-one,two,three
-four,five
-six,seven,eight
-nine,ten,eleven,twelve
+++ /dev/null
-"one","two","three"
-"four","five"
-"six","seven","eight"
-"nine","ten","eleven","twelve"
+++ /dev/null
-<?php
-/**
- * @package File_CSV
- */
-
-require_once dirname(__FILE__) . '/../CSV.php';
-
-function test_csv()
-{
- foreach (func_get_args() as $file) {
- $file = dirname(__FILE__) . '/' . $file . '.csv';
- $conf = File_CSV::discoverFormat($file);
- if (is_a($conf, 'PEAR_Error')) {
- var_dump($conf);
- return;
- }
- $csv = array();
- while ($row = File_CSV::read($file, $conf)) {
- if (is_a($row, 'PEAR_Error')) {
- var_dump($row);
- return;
- }
- $csv[] = $row;
- }
- var_dump($csv);
- $warnings = File_CSV::warning();
- if (count($warnings)) {
- var_dump($warnings);
- }
- }
-}
+++ /dev/null
---TEST--
-File_CSV: linebreak tests
---FILE--
-<?php
-
-require dirname(__FILE__) . '/common.php';
-test_csv('simple_cr', 'simple_lf', 'simple_crlf', 'notrailing_lf', 'notrailing_crlf');
-
-?>
---EXPECT--
-array(2) {
- [0]=>
- array(3) {
- [0]=>
- string(3) "one"
- [1]=>
- string(3) "two"
- [2]=>
- string(5) "three"
- }
- [1]=>
- array(3) {
- [0]=>
- string(4) "four"
- [1]=>
- string(4) "five"
- [2]=>
- string(3) "six"
- }
-}
-array(2) {
- [0]=>
- array(3) {
- [0]=>
- string(3) "one"
- [1]=>
- string(3) "two"
- [2]=>
- string(5) "three"
- }
- [1]=>
- array(3) {
- [0]=>
- string(4) "four"
- [1]=>
- string(4) "five"
- [2]=>
- string(3) "six"
- }
-}
-array(2) {
- [0]=>
- array(3) {
- [0]=>
- string(3) "one"
- [1]=>
- string(3) "two"
- [2]=>
- string(5) "three"
- }
- [1]=>
- array(3) {
- [0]=>
- string(4) "four"
- [1]=>
- string(4) "five"
- [2]=>
- string(3) "six"
- }
-}
-array(2) {
- [0]=>
- array(3) {
- [0]=>
- string(3) "one"
- [1]=>
- string(3) "two"
- [2]=>
- string(5) "three"
- }
- [1]=>
- array(3) {
- [0]=>
- string(4) "four"
- [1]=>
- string(4) "five"
- [2]=>
- string(3) "six"
- }
-}
-array(2) {
- [0]=>
- array(3) {
- [0]=>
- string(3) "one"
- [1]=>
- string(3) "two"
- [2]=>
- string(5) "three"
- }
- [1]=>
- array(3) {
- [0]=>
- string(4) "four"
- [1]=>
- string(4) "five"
- [2]=>
- string(3) "six"
- }
-}
+++ /dev/null
---TEST--
-File_CSV: multiline tests
---FILE--
-<?php
-
-require dirname(__FILE__) . '/common.php';
-test_csv('multiline1');
-
-?>
---EXPECT--
-array(4) {
- [0]=>
- array(3) {
- [0]=>
- string(3) "one"
- [1]=>
- string(3) "two"
- [2]=>
- string(10) "three
-four"
- }
- [1]=>
- array(3) {
- [0]=>
- string(4) "five"
- [1]=>
- string(9) "six
-seven"
- [2]=>
- string(5) "eight"
- }
- [2]=>
- array(3) {
- [0]=>
- string(4) "nine"
- [1]=>
- string(3) "ten"
- [2]=>
- string(14) "eleven
-twelve"
- }
- [3]=>
- array(3) {
- [0]=>
- string(3) "one"
- [1]=>
- string(3) "two"
- [2]=>
- string(11) "three
- four"
- }
-}
+++ /dev/null
-"one","two","three
-four"
-"five","six
-seven","eight"
-"nine","ten","eleven
-twelve"
-"one","two","three
- four"
+++ /dev/null
-one,two,three
-four,five,six
+++ /dev/null
-one,two,three
-four,five,six
+++ /dev/null
-"one",two,"three"
-four,"five six",seven
+++ /dev/null
-"one",two,"three"
-four,"five six",seven
+++ /dev/null
-"one two","three, four",five
-six,"seven ",eight
-
+++ /dev/null
-"one two","three, four",five
-six,"seven ",eight
-
+++ /dev/null
-"one two","three, four","five"
-"six","seven ","eight"
+++ /dev/null
---TEST--
-File_CSV: quote tests
---FILE--
-<?php
-
-require dirname(__FILE__) . '/common.php';
-test_csv('quote1', 'quote2', 'quote3', 'quote4', 'quote5');
-
-?>
---EXPECT--
-array(2) {
- [0]=>
- array(3) {
- [0]=>
- string(3) "one"
- [1]=>
- string(3) "two"
- [2]=>
- string(5) "three"
- }
- [1]=>
- array(3) {
- [0]=>
- string(4) "four"
- [1]=>
- string(8) "five six"
- [2]=>
- string(5) "seven"
- }
-}
-array(2) {
- [0]=>
- array(3) {
- [0]=>
- string(3) "one"
- [1]=>
- string(3) "two"
- [2]=>
- string(5) "three"
- }
- [1]=>
- array(3) {
- [0]=>
- string(4) "four"
- [1]=>
- string(8) "five six"
- [2]=>
- string(5) "seven"
- }
-}
-array(2) {
- [0]=>
- array(3) {
- [0]=>
- string(7) "one two"
- [1]=>
- string(11) "three, four"
- [2]=>
- string(4) "five"
- }
- [1]=>
- array(3) {
- [0]=>
- string(3) "six"
- [1]=>
- string(6) "seven "
- [2]=>
- string(5) "eight"
- }
-}
-array(2) {
- [0]=>
- array(3) {
- [0]=>
- string(7) "one two"
- [1]=>
- string(11) "three, four"
- [2]=>
- string(4) "five"
- }
- [1]=>
- array(3) {
- [0]=>
- string(3) "six"
- [1]=>
- string(6) "seven "
- [2]=>
- string(5) "eight"
- }
-}
-array(2) {
- [0]=>
- array(3) {
- [0]=>
- string(7) "one two"
- [1]=>
- string(11) "three, four"
- [2]=>
- string(4) "five"
- }
- [1]=>
- array(3) {
- [0]=>
- string(3) "six"
- [1]=>
- string(6) "seven "
- [2]=>
- string(5) "eight"
- }
-}
+++ /dev/null
-one,two,three\rfour,five,six\r
\ No newline at end of file
+++ /dev/null
-one,two,three
-four,five,six
+++ /dev/null
-one,two,three
-four,five,six
--- /dev/null
+<?php
+/**
+ * Provide reading and creating of CSV data and files.
+ *
+ * Copyright 2002-2003 Tomas Von Veschler Cox <cox@idecnet.com>
+ * Copyright 2005-2010 The Horde Project (http://www.horde.org/)
+ *
+ * This source file is subject to version 2.0 of the PHP license, that is
+ * bundled with this package in the file LICENSE, and is available at through
+ * the world-wide-web at http://www.php.net/license/2_02.txt. If you did not
+ * receive a copy of the PHP license and are unable to obtain it through the
+ * world-wide-web, please send a note to license@php.net so we can mail you a
+ * copy immediately.
+ *
+ * @author Tomas Von Veschler Cox <cox@idecnet.com>
+ * @author Jan Schneider <jan@horde.org>
+ * @category Horde
+ * @package Horde_File_Csv
+ */
+class Horde_File_Csv
+{
+ /** Mode to use for reading from files */
+ const MODE_READ = 'rb';
+
+ /** Mode to use for truncating files, then writing */
+ const MODE_WRITE = 'wb';
+
+ /** Mode to use for appending to files */
+ const MODE_APPEND = 'ab';
+
+ /**
+ * Discovers the format of a CSV file (the number of fields, the
+ * separator, the quote string, and the line break).
+ *
+ * We can't use the auto_detect_line_endings PHP setting, because it's not
+ * supported by fgets() contrary to what the manual says.
+ *
+ * @param string $file The CSV file name
+ * @param array $extraSeps Extra separators that should be checked for.
+ *
+ * @return array The format hash.
+ * @throws Horde_File_Csv_Exception
+ */
+ static public function discoverFormat($file, $extraSeps = array())
+ {
+ if (!$fp = @fopen($file, 'r')) {
+ throw new Horde_File_Csv_Exception('Could not open file: ' . $file);
+ }
+
+ $seps = array("\t", ';', ':', ',', '~');
+ $seps = array_merge($seps, $extraSeps);
+ $conf = $matches = array();
+ $crlf = null;
+
+ /* Take the first 10 lines and store the number of ocurrences for each
+ * separator in each line. */
+ for ($i = 0; ($i < 10) && ($line = fgets($fp));) {
+ /* Do we have Mac line endings? */
+ $lines = preg_split('/\r(?!\n)/', $line, 10);
+ $j = 0;
+ $c = count($lines);
+ if ($c > 1) {
+ $crlf = "\r";
+ }
+ while ($i < 10 && $j < $c) {
+ $line = $lines[$j];
+ if (!isset($crlf)) {
+ foreach (array("\r\n", "\n") as $c) {
+ if (substr($line, -strlen($c)) == $c) {
+ $crlf = $c;
+ break;
+ }
+ }
+ }
+ ++$i;
+ ++$j;
+ foreach ($seps as $sep) {
+ $matches[$sep][$i] = substr_count($line, $sep);
+ }
+ }
+ }
+
+ if (isset($crlf)) {
+ $conf['crlf'] = $crlf;
+ }
+
+ /* Group the results by amount of equal occurrences. */
+ $amount = $fields = array();
+ foreach ($matches as $sep => $lines) {
+ $times = array(0 => 0);
+ foreach ($lines as $num) {
+ if ($num > 0) {
+ $times[$num] = (isset($times[$num])) ? $times[$num] + 1 : 1;
+ }
+ }
+ arsort($times);
+ $fields[$sep] = key($times);
+ $amount[$sep] = $times[key($times)];
+ }
+ arsort($amount);
+ $sep = key($amount);
+
+ $conf['fields'] = $fields[$sep] + 1;
+ $conf['sep'] = $sep;
+
+ /* Test if there are fields with quotes around in the first 10
+ * lines. */
+ $quotes = '"\'';
+ $quote = '';
+ rewind($fp);
+ for ($i = 0; ($i < 10) && ($line = fgets($fp)); ++$i) {
+ if (preg_match("|$sep([$quotes]).*([$quotes])$sep|U", $line, $match)) {
+ if ($match[1] == $match[2]) {
+ $quote = $match[1];
+ break;
+ }
+ }
+ if (preg_match("|^([$quotes]).*([$quotes])$sep|", $line, $match) ||
+ preg_match("|([$quotes]).*([$quotes])$sep\s$|Us", $line, $match)) {
+ if ($match[1] == $match[2]) {
+ $quote = $match[1];
+ break;
+ }
+ }
+ }
+ $conf['quote'] = $quote;
+
+ fclose($fp);
+
+ // XXX What about trying to discover the "header"?
+ return $conf;
+ }
+
+ /**
+ * Reads a row from a CSV file and returns it as an array.
+ *
+ * This method normalizes linebreaks to single newline characters (0x0a).
+ *
+ * @param string $file The name of the CSV file.
+ * @param array $conf The configuration for the CSV file.
+ *
+ * @return array|boolean The CSV data or false if no more data available.
+ * @throws Horde_File_Csv_Exception
+ */
+ static public function read($file, &$conf)
+ {
+ $fp = self::getPointer($file, $conf, self::MODE_READ);
+
+ $line = fgets($fp);
+ $line_length = strlen($line);
+
+ /* Use readQuoted() if we have Mac line endings. */
+ if (preg_match('/\r(?!\n)/', $line)) {
+ fseek($fp, -$line_length, SEEK_CUR);
+ return self::readQuoted($file, $conf);
+ }
+
+ /* Normalize line endings. */
+ $line = str_replace("\r\n", "\n", $line);
+ if (!strlen(trim($line))) {
+ return false;
+ }
+
+ self::_line(self::_line() + 1);
+
+ if ($conf['fields'] == 1) {
+ return array($line);
+ }
+
+ $fields = explode($conf['sep'], $line);
+ if ($conf['quote']) {
+ $last = ltrim($fields[count($fields) - 1]);
+ /* Fallback to read the line with readQuoted() if we assume that
+ * the simple explode won't work right. */
+ $last_len = strlen($last);
+ if (($last_len &&
+ $last[$last_len - 1] == "\n" &&
+ $last[0] == $conf['quote'] &&
+ $last[strlen(rtrim($last)) - 1] != $conf['quote']) ||
+ (count($fields) != $conf['fields'])
+ // XXX perhaps there is a separator inside a quoted field
+ // preg_match("|{$conf['quote']}.*{$conf['sep']}.*{$conf['quote']}|U", $line)
+ ) {
+ fseek($fp, -$line_length, SEEK_CUR);
+ return self::readQuoted($file, $conf);
+ } else {
+ foreach ($fields as $k => $v) {
+ $fields[$k] = self::unquote(trim($v), $conf['quote']);
+ }
+ }
+ } else {
+ foreach ($fields as $k => $v) {
+ $fields[$k] = trim($v);
+ }
+ }
+
+ if (count($fields) < $conf['fields']) {
+ self::warning(sprintf(_("Wrong number of fields in line %d. Expected %d, found %d."), self::_line(), $conf['fields'], count($fields)));
+ $fields = array_merge($fields, array_fill(0, $conf['fields'] - count($fields), ''));
+ } elseif (count($fields) > $conf['fields']) {
+ self::warning(sprintf(_("More fields found in line %d than the expected %d."), self::_line(), $conf['fields']));
+ array_splice($fields, $conf['fields']);
+ }
+
+ return $fields;
+ }
+
+ /**
+ * Reads a row from a CSV file and returns it as an array.
+ *
+ * This method is able to read fields with multiline data and normalizes
+ * linebreaks to single newline characters (0x0a).
+ *
+ * @param string $file The name of the CSV file.
+ * @param array $conf The configuration for the CSV file.
+ *
+ * @return array|boolean The CSV data or false if no more data available.
+ * @throws Horde_File_Csv_Exception
+ */
+ static public function readQuoted($file, &$conf)
+ {
+ $fp = self::getPointer($file, $conf, self::MODE_READ);
+
+ /* A buffer with all characters of the current field read so far. */
+ $buff = '';
+ /* The current character. */
+ $c = null;
+ /* The read fields. */
+ $ret = false;
+ /* The number of the current field. */
+ $i = 0;
+ /* Are we inside a quoted field? */
+ $in_quote = false;
+ /* Did we just process an escaped quote? */
+ $quote_escaped = false;
+ /* Is the last processed quote the first of a field? */
+ $first_quote = false;
+
+ while (($ch = fgetc($fp)) !== false) {
+ /* Normalize line breaks. */
+ if ($ch == $conf['crlf']) {
+ $ch = "\n";
+ } elseif (strlen($conf['crlf']) == 2 && $ch == $conf['crlf'][0]) {
+ $next = fgetc($fp);
+ if (!$next) {
+ break;
+ }
+ if ($next == $conf['crlf'][1]) {
+ $ch = "\n";
+ }
+ }
+
+ /* Previous character. */
+ $prev = $c;
+ /* Current character. */
+ $c = $ch;
+
+ /* Simple character. */
+ if ($c != $conf['quote'] &&
+ $c != $conf['sep'] &&
+ $c != "\n") {
+ $buff .= $c;
+ if (!$i) {
+ $i = 1;
+ }
+ $first_quote = $quote_escaped = false;
+ continue;
+ }
+
+ if ($c == $conf['quote'] && !$in_quote) {
+ /* Quoted field begins. */
+ $in_quote = true;
+ $buff = '';
+ if (!$i) {
+ $i = 1;
+ }
+ } elseif ($in_quote) {
+ /* We do NOT check for the closing quote immediately, but when
+ * we got the character AFTER the closing quote. */
+ if ($c == $conf['quote'] && $prev == $conf['quote'] &&
+ !$quote_escaped) {
+ /* Escaped (double) quotes. */
+ $first_quote = $quote_escaped = true;
+ $prev = null;
+ /* Simply skip the second quote. */
+ continue;
+ } elseif ($c == $conf['sep'] && $prev == $conf['quote']) {
+ /* Quoted field ends with a delimiter. */
+ $in_quote = $quote_escaped = false;
+ $first_quote = true;
+ } elseif ($c == "\n") {
+ /* We have a linebreak inside the quotes. */
+ if (strlen($buff) == 1 &&
+ $buff[0] == $conf['quote'] &&
+ $quote_escaped && $first_quote) {
+ /* A line break after a closing quote of an empty
+ * field, field and row end here. */
+ $in_quote = false;
+ } elseif (strlen($buff) >= 1 &&
+ $buff[strlen($buff) - 1] == $conf['quote'] &&
+ !$quote_escaped && !$first_quote) {
+ /* A line break after a closing quote, field and row
+ * end here. This is NOT the closing quote if we
+ * either process an escaped (double) quote, or if the
+ * quote before the line break was the opening
+ * quote. */
+ $in_quote = false;
+ } else {
+ /* Only increment the line number. Line breaks inside
+ * quoted fields are part of the field content. */
+ self::_line(self::_line() + 1);
+ }
+ $quote_escaped = false;
+ $first_quote = true;
+ }
+ }
+
+ if (!$in_quote &&
+ ($c == $conf['sep'] || $c == "\n")) {
+ /* End of line or end of field. */
+ if ($c == $conf['sep'] &&
+ (count($ret) + 1) == $conf['fields']) {
+ /* More fields than expected. Forward the line pointer to
+ * the EOL and drop the remainder. */
+ while ($c !== false && $c != "\n") {
+ $c = fgetc($fp);
+ }
+ self::warning(sprintf('More fields found in line %d than the expected %d.', self::_line(), $conf['fields']));
+ }
+
+ if ($c == "\n" &&
+ $i != $conf['fields']) {
+ /* Less fields than expected. */
+ if ($i == 0) {
+ /* Skip empty lines. */
+ return $ret;
+ }
+ self::warning(sprintf('Wrong number of fields in line %d. Expected %d, found %d.', self::_line(), $conf['fields'], $i));
+
+ $ret[] = self::unquote($buff, $conf['quote']);
+ return array_merge($ret, array_fill(0, $conf['fields'] - $i, ''));
+ }
+
+ /* Remove surrounding quotes from quoted fields. */
+ $ret[] = ($buff == '"')
+ ? ''
+ : self::unquote($buff, $conf['quote']);
+ if (count($ret) == $conf['fields']) {
+ return $ret;
+ }
+
+ $buff = '';
+ ++$i;
+ continue;
+ }
+ $buff .= $c;
+ }
+
+ return $ret;
+ }
+
+ /**
+ * Writes a hash into a CSV file.
+ *
+ * @param string $file The name of the CSV file.
+ * @param array $fields The CSV data.
+ * @param array $conf The configuration for the CSV file.
+ *
+ * @throws Horde_File_Csv_Exception
+ */
+ static public function write($file, $fields, &$conf)
+ {
+ $fp = self::getPointer($file, $conf, self::MODE_WRITE);
+
+ if (count($fields) != $conf['fields']) {
+ throw new Horde_File_Csv_Exception(sprintf('Wrong number of fields. Expected %d, found %d.', $conf['fields'], count($fields)));
+ }
+
+ $write = '';
+ for ($i = 0; $i < count($fields); ++$i) {
+ $write .= (!is_numeric($fields[$i]) && $conf['quote'])
+ ? $conf['quote'] . $fields[$i] . $conf['quote']
+ : $fields[$i];
+ $write .= ($i < (count($fields) - 1))
+ ? $conf['sep']
+ : $conf['crlf'];
+ }
+
+ if (!fwrite($fp, $write)) {
+ throw new Horde_File_Csv_Exception(sprintf('Cannot write to file "%s"', $file));
+ }
+
+ fclose($fp);
+ }
+
+ /**
+ * Removes surrounding quotes from a string and normalizes linebreaks.
+ *
+ * @param string $field The string to unquote.
+ * @param string $quote The quote character.
+ * @param string $crlf The linebreak character.
+ *
+ * @return string The unquoted data.
+ */
+ static public function unquote($field, $quote, $crlf = null)
+ {
+ /* Skip empty fields (form: ;;) */
+ if (!strlen($field)) {
+ return $field;
+ }
+
+ if ($quote && $field[0] == $quote &&
+ $field[strlen($field) - 1] == $quote) {
+ /* Normalize only for BC. */
+ if ($crlf) {
+ $field = str_replace($crlf, "\n", $field);
+ }
+ return substr($field, 1, -1);
+ }
+
+ return $field;
+ }
+
+ /**
+ * Sets or gets the current line being parsed.
+ *
+ * @param integer $line If specified, the current line.
+ *
+ * @return integer The current line.
+ */
+ static protected function _line($line = null)
+ {
+ static $current_line = 0;
+
+ if (!is_null($line)) {
+ $current_line = $line;
+ }
+
+ return $current_line;
+ }
+
+ /**
+ * Adds a warning to or retrieves and resets the warning stack.
+ *
+ * @param string A warning string. If not specified, the existing
+ * warnings will be returned instead and the warning stack
+ * gets emptied.
+ *
+ * @return array If no parameter has been specified, the list of existing
+ * warnings.
+ */
+ static public function warning($warning = null)
+ {
+ static $warnings = array();
+
+ if (is_null($warning)) {
+ $return = $warnings;
+ $warnings = array();
+ return $return;
+ }
+
+ $warnings[] = $warning;
+ }
+
+ /**
+ * Returns or creates the file descriptor associated with a file.
+ *
+ * @param string $file The name of the file
+ * @param array $conf The configuration
+ * @param string $mode The open mode. self::MODE_READ or
+ * self::MODE_WRITE.
+ *
+ * @return resource The file resource.
+ *
+ * @throws Horde_File_Csv_Exception
+ */
+ static public function getPointer($file, &$conf, $mode = self::MODE_READ)
+ {
+ static $resources = array();
+ static $config = array();
+
+ if (isset($resources[$file])) {
+ $conf = $config[$file];
+ return $resources[$file];
+ }
+
+ if (!is_array($conf)) {
+ throw new Horde_File_Csv_Exception('Invalid configuration.');
+ }
+
+ if (!isset($conf['fields']) || !is_numeric($conf['fields'])) {
+ throw new Horde_File_Csv_Exception('The number of fields must be numeric.');
+ }
+
+ if (isset($conf['sep'])) {
+ if (strlen($conf['sep']) != 1) {
+ throw new Horde_File_Csv_Exception('The separator must be one single character.');
+ }
+ } elseif ($conf['fields'] > 1) {
+ throw new Horde_File_Csv_Exception('No separator specified.');
+ }
+
+ if (!empty($conf['quote'])) {
+ if (strlen($conf['quote']) != 1) {
+ throw new Horde_File_Csv_Exception('The quote character must be one single character.');
+ }
+ } else {
+ $conf['quote'] = '';
+ }
+
+ if (!isset($conf['crlf'])) {
+ $conf['crlf'] = "\n";
+ }
+
+ $config[$file] = $conf;
+
+ $fp = @fopen($file, $mode);
+ if (!is_resource($fp)) {
+ throw new Horde_File_Csv_Exception(sprintf('Cannot open file "%s".', $file));
+ }
+ $resources[$file] = $fp;
+ self::_line(0);
+
+ if (($mode == self::MODE_READ) && !empty($conf['header'])) {
+ self::read($file, $conf);
+ }
+
+ return $fp;
+ }
+
+}
--- /dev/null
+<?php
+/**
+ * Exception handler for the Horde_File_Csv package.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * This source file is subject to version 2.0 of the PHP license, that is
+ * bundled with this package in the file LICENSE, and is available at through
+ * the world-wide-web at http://www.php.net/license/2_02.txt. If you did not
+ * receive a copy of the PHP license and are unable to obtain it through the
+ * world-wide-web, please send a note to license@php.net so we can mail you a
+ * copy immediately.
+ *
+ * @author Michael Slusarz <slusarz@horde.org>
+ * @category Horde
+ * @package Horde_File_Csv
+ */
+class Horde_File_Csv_Exception extends Horde_Exception
+{
+}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<package packagerversion="1.4.9" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0
+http://pear.php.net/dtd/tasks-1.0.xsd
+http://pear.php.net/dtd/package-2.0
+http://pear.php.net/dtd/package-2.0.xsd">
+ <name>File_Csv</name>
+ <channel>pear.horde.org</channel>
+ <summary>Reads and writes CSV files</summary>
+ <description>This package allows reading and creating of CSV data and files. It
+is a fork of the File_CSV class of PEAR's File package.
+ </description>
+ <lead>
+ <name>Jan Schneider</name>
+ <user>jan</user>
+ <email>jan@horde.org</email>
+ <active>yes</active>
+ </lead>
+ <date>2010-02-03</date>
+ <version>
+ <release>0.2.0</release>
+ <api>0.2.0</api>
+ </version>
+ <stability>
+ <release>beta</release>
+ <api>beta</api>
+ </stability>
+ <license uri="http://www.php.net/license">PHP</license>
+ <notes>* Initial Horde 4 Package
+ </notes>
+ <contents>
+ <dir name="/">
+ <dir name="lib">
+ <dir name="Horde">
+ <dir name="Csv">
+ <file name="Exception.php" role="php" />
+ </dir> <!-- /lib/Horde/Csv -->
+ <file name="Csv.php" role="php" />
+ </dir> <!-- /lib/Horde -->
+ </dir> <!-- /lib -->
+ <dir name="test">
+ <dir name="Horde">
+ <dir name="Csv">
+ <file name="bug_3839.csv" role="test" />
+ <file name="bug_3839.phpt" role="test" />
+ <file name="columns.phpt" role="test" />
+ <file name="columns1.csv" role="test" />
+ <file name="common.php" role="test" />
+ <file name="multiline.phpt" role="test" />
+ <file name="multiline1.csv" role="test" />
+ <file name="notrailing_crlf.csv" role="test" />
+ <file name="notrailing_lf.csv" role="test" />
+ <file name="quote1.csv" role="test" />
+ <file name="quote2.csv" role="test" />
+ <file name="quote3.csv" role="test" />
+ <file name="quote4.csv" role="test" />
+ <file name="quote5.csv" role="test" />
+ <file name="quotes.phpt" role="test" />
+ <file name="simple_cr.csv" role="test" />
+ <file name="simple_crlf.csv" role="test" />
+ <file name="simple_lf.csv" role="test" />
+ </dir> <!-- /test/Horde/Csv -->
+ </dir> <!-- /test/Horde -->
+ </dir> <!-- /test -->
+ </dir> <!-- / -->
+ </contents>
+ <dependencies>
+ <required>
+ <php>
+ <min>5.2.0</min>
+ </php>
+ <pearinstaller>
+ <min>1.5.0</min>
+ </pearinstaller>
+ <package>
+ <name>PEAR</name>
+ <channel>pear.php.net</channel>
+ </package>
+ <extension>
+ <name>pcre</name>
+ </extension>
+ </required>
+ </dependencies>
+ <phprelease>
+ <filelist>
+ <install name="lib/Horde/Csv/Exception.php" as="Horde/Csv/Exception.php" />
+ <install name="lib/Horde/Csv.php" as="Horde/Csv.php" />
+ </filelist>
+ </phprelease>
+ <changelog>
+ <release>
+ <date>2006-05-08</date>
+ <time>21:32:31</time>
+ <version>
+ <release>0.1.1</release>
+ <api>0.1.1</api>
+ </version>
+ <stability>
+ <release>beta</release>
+ <api>beta</api>
+ </stability>
+ <license uri="http://www.php.net/license">PHP</license>
+ <notes>
+ * Converted to package.xml 2.0 for pear.horde.org
+ * Close Horde bug #6372 (ritaselsky@gmail.com)
+ </notes>
+ </release>
+ <release>
+ <version>
+ <release>0.1.0</release>
+ <api>0.1.0</api>
+ </version>
+ <stability>
+ <release>beta</release>
+ <api>beta</api>
+ </stability>
+ <date>2004-01-01</date>
+ <license uri="http://www.php.net/license">PHP</license>
+ <notes>First release.
+ </notes>
+ </release>
+ </changelog>
+</package>
--- /dev/null
+"Field 1-1", "Field 1-2", "Field 1-3", "Field 1-4"
+"Field 2-1", "Field 2-2", "Field 2-3"
+"Field 3-1", "Field 3-2"
+"Field 4-1"
--- /dev/null
+--TEST--
+Horde_File_Csv Test Case 001: Fields count less than expected
+--FILE--
+<?php
+/**
+ * Test for:
+ * - Horde_File_Csv::discoverFormat()
+ * - Horde_File_Csv::readQuoted()
+ */
+
+require_once dirname(__FILE__) . '/../../../lib/Horde/Csv.php';
+
+$file = dirname(__FILE__) . '/001.csv';
+$conf = Horde_File_Csv::discoverFormat($file);
+$conf['fields'] = 4;
+
+var_dump($conf);
+
+$data = array();
+while ($res = Horde_File_Csv::readQuoted($file, $conf)) {
+ $data[] = $res;
+}
+
+var_dump($data);
+
+?>
+--EXPECT--
+array(4) {
+ ["crlf"]=>
+ string(1) "
+"
+ ["fields"]=>
+ int(4)
+ ["sep"]=>
+ string(1) ","
+ ["quote"]=>
+ string(1) """
+}
+array(4) {
+ [0]=>
+ array(4) {
+ [0]=>
+ string(9) "Field 1-1"
+ [1]=>
+ string(9) "Field 1-2"
+ [2]=>
+ string(9) "Field 1-3"
+ [3]=>
+ string(9) "Field 1-4"
+ }
+ [1]=>
+ array(4) {
+ [0]=>
+ string(9) "Field 2-1"
+ [1]=>
+ string(9) "Field 2-2"
+ [2]=>
+ string(9) "Field 2-3"
+ [3]=>
+ string(0) ""
+ }
+ [2]=>
+ array(4) {
+ [0]=>
+ string(9) "Field 3-1"
+ [1]=>
+ string(9) "Field 3-2"
+ [2]=>
+ string(0) ""
+ [3]=>
+ string(0) ""
+ }
+ [3]=>
+ array(4) {
+ [0]=>
+ string(9) "Field 4-1"
+ [1]=>
+ string(0) ""
+ [2]=>
+ string(0) ""
+ [3]=>
+ string(0) ""
+ }
+}
--- /dev/null
+"Field 1-1", "Field 1-2", "Field 1-3", "Field 1-4"
+"Field 2-1", "Field 2-2", "Field 2-3", "Field 2-4", "Extra Field"
+"Field 3-1", "Field 3-2"
+"Field 4-1"
--- /dev/null
+--TEST--
+Horde_File_Csv Test Case 002: Fields count more than expected
+--FILE--
+<?php
+/**
+ * Test for:
+ * - Horde_File_Csv::discoverFormat()
+ * - Horde_File_Csv::readQuoted()
+ */
+
+require_once dirname(__FILE__) . '/../../../lib/Horde/Csv.php';
+
+$file = dirname(__FILE__) . '/002.csv';
+$conf = Horde_File_Csv::discoverFormat($file);
+$conf['fields'] = 4;
+
+var_dump($conf);
+
+$data = array();
+while ($res = Horde_File_Csv::readQuoted($file, $conf)) {
+ $data[] = $res;
+}
+
+var_dump($data);
+
+?>
+--EXPECT--
+array(4) {
+ ["crlf"]=>
+ string(1) "
+"
+ ["fields"]=>
+ int(4)
+ ["sep"]=>
+ string(1) ","
+ ["quote"]=>
+ string(1) """
+}
+array(4) {
+ [0]=>
+ array(4) {
+ [0]=>
+ string(9) "Field 1-1"
+ [1]=>
+ string(9) "Field 1-2"
+ [2]=>
+ string(9) "Field 1-3"
+ [3]=>
+ string(9) "Field 1-4"
+ }
+ [1]=>
+ array(4) {
+ [0]=>
+ string(9) "Field 2-1"
+ [1]=>
+ string(9) "Field 2-2"
+ [2]=>
+ string(9) "Field 2-3"
+ [3]=>
+ string(9) "Field 2-4"
+ }
+ [2]=>
+ array(4) {
+ [0]=>
+ string(9) "Field 3-1"
+ [1]=>
+ string(9) "Field 3-2"
+ [2]=>
+ string(0) ""
+ [3]=>
+ string(0) ""
+ }
+ [3]=>
+ array(4) {
+ [0]=>
+ string(9) "Field 4-1"
+ [1]=>
+ string(0) ""
+ [2]=>
+ string(0) ""
+ [3]=>
+ string(0) ""
+ }
+}
--- /dev/null
+"Field 1-1","Field 1-2","Field 1-3","Field 1-4"
+"Field 2-1","Field 2-2","Field 2-3","I'm multiline
+Field"
+"Field 3-1","Field 3-2","Field 3-3"
--- /dev/null
+--TEST--
+Horde_File_Csv Test Case 003: Windows EOL
+--FILE--
+<?php
+/**
+ * Test for:
+ * - Horde_File_Csv::discoverFormat()
+ * - Horde_File_Csv::readQuoted()
+ */
+
+require_once dirname(__FILE__) . '/../CSV.php';
+
+$file = dirname(__FILE__) . '/003.csv';
+$conf = Horde_File_Csv::discoverFormat($file);
+
+print "Format:\n";
+print_r($conf);
+print "\n";
+
+$data = array();
+while ($res = Horde_File_Csv::readQuoted($file, $conf)) {
+ $data[] = $res;
+}
+
+print "Data:\n";
+print_r($data);
+?>
+--EXPECT--
+Format:
+Array
+(
+ [crlf] =>
+
+ [fields] => 4
+ [sep] => ,
+ [quote] => "
+)
+
+Data:
+Array
+(
+ [0] => Array
+ (
+ [0] => Field 1-1
+ [1] => Field 1-2
+ [2] => Field 1-3
+ [3] => Field 1-4
+ )
+
+ [1] => Array
+ (
+ [0] => Field 2-1
+ [1] => Field 2-2
+ [2] => Field 2-3
+ [3] => I'm multiline
+Field
+ )
+
+ [2] => Array
+ (
+ [0] => Field 3-1
+ [1] => Field 3-2
+ [2] => Field 3-3
+ [3] =>
+ )
+
+)
--- /dev/null
+"Field 1-1","Field 1-2","Field 1-3","Field 1-4"
+"Field 2-1","Field 2-2","Field 2-3","I'm multiline
+Field"
+"Field 3-1","Field 3-2","Field 3-3"
--- /dev/null
+--TEST--
+Horde_File_Csv Test Case 004: Unix EOL
+--FILE--
+<?php
+/**
+ * Test for:
+ * - Horde_File_Csv::discoverFormat()
+ * - Horde_File_Csv::readQuoted()
+ */
+
+require_once dirname(__FILE__) . '/../../../lib/Horde/Csv.php';
+
+$file = dirname(__FILE__) . '/004.csv';
+$conf = Horde_File_Csv::discoverFormat($file);
+
+print "Format:\n";
+print_r($conf);
+print "\n";
+
+$data = array();
+while ($res = Horde_File_Csv::readQuoted($file, $conf)) {
+ $data[] = $res;
+}
+
+print "Data:\n";
+print_r($data);
+?>
+--EXPECT--
+Format:
+Array
+(
+ [crlf] =>
+
+ [fields] => 4
+ [sep] => ,
+ [quote] => "
+)
+
+Data:
+Array
+(
+ [0] => Array
+ (
+ [0] => Field 1-1
+ [1] => Field 1-2
+ [2] => Field 1-3
+ [3] => Field 1-4
+ )
+
+ [1] => Array
+ (
+ [0] => Field 2-1
+ [1] => Field 2-2
+ [2] => Field 2-3
+ [3] => I'm multiline
+Field
+ )
+
+ [2] => Array
+ (
+ [0] => Field 3-1
+ [1] => Field 3-2
+ [2] => Field 3-3
+ [3] =>
+ )
+
+)
--- /dev/null
+"Field 1-1","Field 1-2","Field 1-3","Field 1-4"\r"Field 2-1","Field 2-2","Field 2-3","I'm multiline\rField"\r"Field 3-1","Field 3-2","Field 3-3"\r
\ No newline at end of file
--- /dev/null
+--TEST--
+Horde_File_Csv Test Case 005: Mac EOL
+--FILE--
+<?php
+/**
+ * Test for:
+ * - Horde_File_Csv::discoverFormat()
+ * - Horde_File_Csv::readQuoted()
+ */
+
+require_once dirname(__FILE__) . '/../../../lib/Horde/Csv.php';
+
+$file = dirname(__FILE__) . '/005.csv';
+$conf = Horde_File_Csv::discoverFormat($file);
+//$conf['fields'] = 4;
+
+print "Format:\n";
+print_r($conf);
+print "\n";
+
+$data = array();
+while ($res = Horde_File_Csv::readQuoted($file, $conf)) {
+ $data[] = $res;
+}
+
+print "Data:\n";
+print_r($data);
+?>
+--EXPECT--
+Format:
+Array
+(
+ [crlf] =>
+ [fields] => 4
+ [sep] => ,
+ [quote] => "
+)
+
+Data:
+Array
+(
+ [0] => Array
+ (
+ [0] => Field 1-1
+ [1] => Field 1-2
+ [2] => Field 1-3
+ [3] => Field 1-4
+ )
+
+ [1] => Array
+ (
+ [0] => Field 2-1
+ [1] => Field 2-2
+ [2] => Field 2-3
+ [3] => I'm multiline
+Field
+ )
+
+ [2] => Array
+ (
+ [0] => Field 3-1
+ [1] => Field 3-2
+ [2] => Field 3-3
+ [3] =>
+ )
+
+)
--- /dev/null
+Subject~Start Date~Start Time~End Date~End Time~All day event~Reminder on/off~Reminder Date~Reminder Time~Category~Description~Priority
+"Inservice on new resource: ""CPNP Toolkit"""~2004-11-08~10:30 AM~2004-11-08~11:30 AM~FALSE~FALSE~~~Training~"CPN Program ...
+Inservice on new resource: ""CPNP Toolkit""
+
+<b>Registration Deadline: October 27, 2004, noon</b>
+
+<a href=""F041108A-Eval.pdf"" target=""_blank"">
+<img src=""acrobat.gif"" border=""0""></a> <a href=""F041108A-Eval.pdf"" target=""_blank""> Session Evaluation - Eligibility for Prize!</a>
+
+<a href=""F041108A-DI.pdf"" target=""_blank"">
+<img src=""acrobat.gif"" border=""0""></a> <a href=""F041108A-DI.pdf"" target=""_blank""> Dial In Numbers for Sites Registered</a>
+
+<a href=""F041108A.pdf"" target=""_blank"">
+<img src=""acrobat.gif"" border=""0""></a> <a href=""F041108A.pdf"" target=""_blank""> Poster and Registration Form</a>
+
+Facilitator: Manager
+
+preblurb preblurb preblurb preblurb preblurb preblurb preblurb preblurb preblurb ""CPNP Toolkit"". postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb .
+
+postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb
+
+Come check out the new resource!"~Normal
--- /dev/null
+--TEST--
+Horde_File_Csv: test for Bug #3839
+--FILE--
+<?php
+
+require_once dirname(__FILE__) . '/../../../lib/Horde/Csv.php';
+
+$file = dirname(__FILE__) . '/bug_3839.csv';
+
+// Explicit conf since we can't detect these settings. Might be able
+// to improve auto-detection, but it definitely should work with the
+// settings specified explicitly.
+// var_dump(Horde_File_Csv::discoverFormat($file));
+$conf['crlf'] = "\r\n";
+$conf['sep'] = '~';
+$conf['fields'] = 12;
+$conf['quote'] = '"';
+
+$csv = array();
+while ($row = Horde_File_Csv::read($file, $conf)) {
+ if (is_a($row, 'PEAR_Error')) {
+ var_dump($row);
+ return;
+ }
+ $csv[] = $row;
+}
+var_dump($csv);
+$warnings = Horde_File_Csv::warning();
+if (count($warnings)) {
+ var_dump($warnings);
+}
+
+?>
+--EXPECT--
+array(2) {
+ [0]=>
+ array(12) {
+ [0]=>
+ string(7) "Subject"
+ [1]=>
+ string(10) "Start Date"
+ [2]=>
+ string(10) "Start Time"
+ [3]=>
+ string(8) "End Date"
+ [4]=>
+ string(8) "End Time"
+ [5]=>
+ string(13) "All day event"
+ [6]=>
+ string(15) "Reminder on/off"
+ [7]=>
+ string(13) "Reminder Date"
+ [8]=>
+ string(13) "Reminder Time"
+ [9]=>
+ string(8) "Category"
+ [10]=>
+ string(11) "Description"
+ [11]=>
+ string(8) "Priority"
+ }
+ [1]=>
+ array(12) {
+ [0]=>
+ string(41) "Inservice on new resource: "CPNP Toolkit""
+ [1]=>
+ string(10) "2004-11-08"
+ [2]=>
+ string(8) "10:30 AM"
+ [3]=>
+ string(10) "2004-11-08"
+ [4]=>
+ string(8) "11:30 AM"
+ [5]=>
+ string(5) "FALSE"
+ [6]=>
+ string(5) "FALSE"
+ [7]=>
+ string(0) ""
+ [8]=>
+ string(0) ""
+ [9]=>
+ string(8) "Training"
+ [10]=>
+ string(1109) "CPN Program ...
+Inservice on new resource: "CPNP Toolkit"
+
+<b>Registration Deadline: October 27, 2004, noon</b>
+
+<a href="F041108A-Eval.pdf" target="_blank">
+<img src="acrobat.gif" border="0"></a> <a href="F041108A-Eval.pdf" target="_blank"> Session Evaluation - Eligibility for Prize!</a>
+
+<a href="F041108A-DI.pdf" target="_blank">
+<img src="acrobat.gif" border="0"></a> <a href="F041108A-DI.pdf" target="_blank"> Dial In Numbers for Sites Registered</a>
+
+<a href="F041108A.pdf" target="_blank">
+<img src="acrobat.gif" border="0"></a> <a href="F041108A.pdf" target="_blank"> Poster and Registration Form</a>
+
+Facilitator: Manager
+
+preblurb preblurb preblurb preblurb preblurb preblurb preblurb preblurb preblurb "CPNP Toolkit". postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb .
+
+postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb postblurb
+
+Come check out the new resource!"
+ [11]=>
+ string(6) "Normal"
+ }
+}
--- /dev/null
+"Betreff","Beginnt am","Beginnt um","Endet am","Endet um","Ganztägiges Ereignis","Erinnerung Ein/Aus","Erinnerung am","Erinnerung um","Besprechungsplanung","Erforderliche Teilnehmer","Optionale Teilnehmer","Besprechungsressourcen","Abrechnungsinformationen","Beschreibung","Kategorien","Ort","Priorität","Privat","Reisekilometer","Vertraulichkeit","Zeitspanne zeigen als"
+"Burger Download Session","2.5.2006","11:50:00","2.5.2006","13:00:00","Aus","Ein","2.5.2006","11:35:00","Haas, Jörg","Kuhl, Oliver",,,,"
+",,"Burger Upload Station (Burger King)","Normal","Aus",,"Normal","1"
--- /dev/null
+--TEST--
+Horde_File_Csv: test for Bug #4025
+--FILE--
+<?php
+
+require_once dirname(__FILE__) . '/../../../lib/Horde/Csv.php';
+
+$file = dirname(__FILE__) . '/bug_4025.csv';
+
+// Explicit conf since we can't detect these settings. Might be able
+// to improve auto-detection, but it definitely should work with the
+// settings specified explicitly.
+// var_dump(Horde_File_Csv::discoverFormat($file));
+$conf['crlf'] = "\r\n";
+$conf['sep'] = ',';
+$conf['fields'] = 22;
+$conf['quote'] = '"';
+
+$csv = array();
+while ($row = Horde_File_Csv::read($file, $conf)) {
+ if (is_a($row, 'PEAR_Error')) {
+ var_dump($row);
+ return;
+ }
+ $csv[] = $row;
+}
+var_dump($csv);
+$warnings = Horde_File_Csv::warning();
+if (count($warnings)) {
+ var_dump($warnings);
+}
+
+?>
+--EXPECT--
+array(2) {
+ [0]=>
+ array(22) {
+ [0]=>
+ string(7) "Betreff"
+ [1]=>
+ string(10) "Beginnt am"
+ [2]=>
+ string(10) "Beginnt um"
+ [3]=>
+ string(8) "Endet am"
+ [4]=>
+ string(8) "Endet um"
+ [5]=>
+ string(20) "Ganztägiges Ereignis"
+ [6]=>
+ string(18) "Erinnerung Ein/Aus"
+ [7]=>
+ string(13) "Erinnerung am"
+ [8]=>
+ string(13) "Erinnerung um"
+ [9]=>
+ string(19) "Besprechungsplanung"
+ [10]=>
+ string(24) "Erforderliche Teilnehmer"
+ [11]=>
+ string(20) "Optionale Teilnehmer"
+ [12]=>
+ string(22) "Besprechungsressourcen"
+ [13]=>
+ string(24) "Abrechnungsinformationen"
+ [14]=>
+ string(12) "Beschreibung"
+ [15]=>
+ string(10) "Kategorien"
+ [16]=>
+ string(3) "Ort"
+ [17]=>
+ string(9) "Priorität"
+ [18]=>
+ string(6) "Privat"
+ [19]=>
+ string(14) "Reisekilometer"
+ [20]=>
+ string(15) "Vertraulichkeit"
+ [21]=>
+ string(21) "Zeitspanne zeigen als"
+ }
+ [1]=>
+ array(22) {
+ [0]=>
+ string(23) "Burger Download Session"
+ [1]=>
+ string(8) "2.5.2006"
+ [2]=>
+ string(8) "11:50:00"
+ [3]=>
+ string(8) "2.5.2006"
+ [4]=>
+ string(8) "13:00:00"
+ [5]=>
+ string(3) "Aus"
+ [6]=>
+ string(3) "Ein"
+ [7]=>
+ string(8) "2.5.2006"
+ [8]=>
+ string(8) "11:35:00"
+ [9]=>
+ string(10) "Haas, Jörg"
+ [10]=>
+ string(12) "Kuhl, Oliver"
+ [11]=>
+ string(0) ""
+ [12]=>
+ string(0) ""
+ [13]=>
+ string(0) ""
+ [14]=>
+ string(1) "
+"
+ [15]=>
+ string(0) ""
+ [16]=>
+ string(35) "Burger Upload Station (Burger King)"
+ [17]=>
+ string(6) "Normal"
+ [18]=>
+ string(3) "Aus"
+ [19]=>
+ string(0) ""
+ [20]=>
+ string(6) "Normal"
+ [21]=>
+ string(1) "1"
+ }
+}
--- /dev/null
+"Title","First Name","Middle Name","Last Name","Suffix","Company","Department","Job Title","Business Street","Business Street 2","Business Street 3","Business City","Business State","Business Postal Code","Business Country/Region","Home Street","Home Street 2","Home Street 3","Home City","Home State","Home Postal Code","Home Country/Region","Other Street","Other Street 2","Other Street 3","Other City","Other State","Other Postal Code","Other Country/Region","Assistant's Phone","Business Fax","Business Phone","Business Phone 2","Callback","Car Phone","Company Main Phone","Home Fax","Home Phone","Home Phone 2","ISDN","Mobile Phone","Other Fax","Other Phone","Pager","Primary Phone","Radio Phone","TTY/TDD Phone","Telex","Account","Anniversary","Assistant's Name","Billing Information","Birthday","Business Address PO Box","Categories","Children","Directory Server","E-mail Address","E-mail Type","E-mail Display Name","E-mail 2 Address","E-mail 2 Type","E-mail 2 Display Name","E-mail 3 Address","E-mail 3 Type","E-mail 3 Display Name","Gender","Government ID Number","Hobby","Home Address PO Box","Initials","Internet Free Busy","Keywords","Language","Location","Manager's Name","Mileage","Notes","Office Location","Organizational ID Number","Other Address PO Box","Priority","Private","Profession","Referred By","Sensitivity","Spouse","User 1","User 2","User 3","User 4","Web Page"
+"","John","","Smith","","International Inc","","","",,,"","","","","",,,"","","","","",,,"","","","","","(123) 555-1111","(123) 555-2222","","","","","","","","","(123) 555-3333","","","","","","","","","0/0/00","",,"0/0/00",,"Programming",,,"john@example.com","SMTP","John Smith (john@example.com)",,,,,,,"Unspecified","",,,"J.S.","","","","","",,"PHP
+Perl
+Python
+","","",,"Normal","False","",,"Normal","","","","","",""
--- /dev/null
+--TEST--
+Horde_File_Csv: test for Bug #6311
+--FILE--
+<?php
+
+require_once dirname(__FILE__) . '/../../../lib/Horde/Csv.php';
+
+$file = dirname(__FILE__) . '/bug_6311.csv';
+
+// Explicit conf since we can't detect these settings. Might be able
+// to improve auto-detection, but it definitely should work with the
+// settings specified explicitly.
+// var_dump(Horde_File_Csv::discoverFormat($file));
+$conf['crlf'] = "\n";
+$conf['sep'] = ',';
+$conf['fields'] = 92;
+$conf['quote'] = '"';
+
+$csv = array();
+while ($row = Horde_File_Csv::read($file, $conf)) {
+ if (is_a($row, 'PEAR_Error')) {
+ var_dump($row);
+ exit;
+ }
+ $csv[] = $row;
+}
+var_dump($csv);
+$warnings = Horde_File_Csv::warning();
+if (count($warnings)) {
+ var_dump($warnings);
+}
+
+?>
+--EXPECT--
+array(2) {
+ [0]=>
+ array(92) {
+ [0]=>
+ string(5) "Title"
+ [1]=>
+ string(10) "First Name"
+ [2]=>
+ string(11) "Middle Name"
+ [3]=>
+ string(9) "Last Name"
+ [4]=>
+ string(6) "Suffix"
+ [5]=>
+ string(7) "Company"
+ [6]=>
+ string(10) "Department"
+ [7]=>
+ string(9) "Job Title"
+ [8]=>
+ string(15) "Business Street"
+ [9]=>
+ string(17) "Business Street 2"
+ [10]=>
+ string(17) "Business Street 3"
+ [11]=>
+ string(13) "Business City"
+ [12]=>
+ string(14) "Business State"
+ [13]=>
+ string(20) "Business Postal Code"
+ [14]=>
+ string(23) "Business Country/Region"
+ [15]=>
+ string(11) "Home Street"
+ [16]=>
+ string(13) "Home Street 2"
+ [17]=>
+ string(13) "Home Street 3"
+ [18]=>
+ string(9) "Home City"
+ [19]=>
+ string(10) "Home State"
+ [20]=>
+ string(16) "Home Postal Code"
+ [21]=>
+ string(19) "Home Country/Region"
+ [22]=>
+ string(12) "Other Street"
+ [23]=>
+ string(14) "Other Street 2"
+ [24]=>
+ string(14) "Other Street 3"
+ [25]=>
+ string(10) "Other City"
+ [26]=>
+ string(11) "Other State"
+ [27]=>
+ string(17) "Other Postal Code"
+ [28]=>
+ string(20) "Other Country/Region"
+ [29]=>
+ string(17) "Assistant's Phone"
+ [30]=>
+ string(12) "Business Fax"
+ [31]=>
+ string(14) "Business Phone"
+ [32]=>
+ string(16) "Business Phone 2"
+ [33]=>
+ string(8) "Callback"
+ [34]=>
+ string(9) "Car Phone"
+ [35]=>
+ string(18) "Company Main Phone"
+ [36]=>
+ string(8) "Home Fax"
+ [37]=>
+ string(10) "Home Phone"
+ [38]=>
+ string(12) "Home Phone 2"
+ [39]=>
+ string(4) "ISDN"
+ [40]=>
+ string(12) "Mobile Phone"
+ [41]=>
+ string(9) "Other Fax"
+ [42]=>
+ string(11) "Other Phone"
+ [43]=>
+ string(5) "Pager"
+ [44]=>
+ string(13) "Primary Phone"
+ [45]=>
+ string(11) "Radio Phone"
+ [46]=>
+ string(13) "TTY/TDD Phone"
+ [47]=>
+ string(5) "Telex"
+ [48]=>
+ string(7) "Account"
+ [49]=>
+ string(11) "Anniversary"
+ [50]=>
+ string(16) "Assistant's Name"
+ [51]=>
+ string(19) "Billing Information"
+ [52]=>
+ string(8) "Birthday"
+ [53]=>
+ string(23) "Business Address PO Box"
+ [54]=>
+ string(10) "Categories"
+ [55]=>
+ string(8) "Children"
+ [56]=>
+ string(16) "Directory Server"
+ [57]=>
+ string(14) "E-mail Address"
+ [58]=>
+ string(11) "E-mail Type"
+ [59]=>
+ string(19) "E-mail Display Name"
+ [60]=>
+ string(16) "E-mail 2 Address"
+ [61]=>
+ string(13) "E-mail 2 Type"
+ [62]=>
+ string(21) "E-mail 2 Display Name"
+ [63]=>
+ string(16) "E-mail 3 Address"
+ [64]=>
+ string(13) "E-mail 3 Type"
+ [65]=>
+ string(21) "E-mail 3 Display Name"
+ [66]=>
+ string(6) "Gender"
+ [67]=>
+ string(20) "Government ID Number"
+ [68]=>
+ string(5) "Hobby"
+ [69]=>
+ string(19) "Home Address PO Box"
+ [70]=>
+ string(8) "Initials"
+ [71]=>
+ string(18) "Internet Free Busy"
+ [72]=>
+ string(8) "Keywords"
+ [73]=>
+ string(8) "Language"
+ [74]=>
+ string(8) "Location"
+ [75]=>
+ string(14) "Manager's Name"
+ [76]=>
+ string(7) "Mileage"
+ [77]=>
+ string(5) "Notes"
+ [78]=>
+ string(15) "Office Location"
+ [79]=>
+ string(24) "Organizational ID Number"
+ [80]=>
+ string(20) "Other Address PO Box"
+ [81]=>
+ string(8) "Priority"
+ [82]=>
+ string(7) "Private"
+ [83]=>
+ string(10) "Profession"
+ [84]=>
+ string(11) "Referred By"
+ [85]=>
+ string(11) "Sensitivity"
+ [86]=>
+ string(6) "Spouse"
+ [87]=>
+ string(6) "User 1"
+ [88]=>
+ string(6) "User 2"
+ [89]=>
+ string(6) "User 3"
+ [90]=>
+ string(6) "User 4"
+ [91]=>
+ string(8) "Web Page"
+ }
+ [1]=>
+ array(92) {
+ [0]=>
+ string(0) ""
+ [1]=>
+ string(4) "John"
+ [2]=>
+ string(0) ""
+ [3]=>
+ string(5) "Smith"
+ [4]=>
+ string(0) ""
+ [5]=>
+ string(17) "International Inc"
+ [6]=>
+ string(0) ""
+ [7]=>
+ string(0) ""
+ [8]=>
+ string(0) ""
+ [9]=>
+ string(0) ""
+ [10]=>
+ string(0) ""
+ [11]=>
+ string(0) ""
+ [12]=>
+ string(0) ""
+ [13]=>
+ string(0) ""
+ [14]=>
+ string(0) ""
+ [15]=>
+ string(0) ""
+ [16]=>
+ string(0) ""
+ [17]=>
+ string(0) ""
+ [18]=>
+ string(0) ""
+ [19]=>
+ string(0) ""
+ [20]=>
+ string(0) ""
+ [21]=>
+ string(0) ""
+ [22]=>
+ string(0) ""
+ [23]=>
+ string(0) ""
+ [24]=>
+ string(0) ""
+ [25]=>
+ string(0) ""
+ [26]=>
+ string(0) ""
+ [27]=>
+ string(0) ""
+ [28]=>
+ string(0) ""
+ [29]=>
+ string(0) ""
+ [30]=>
+ string(14) "(123) 555-1111"
+ [31]=>
+ string(14) "(123) 555-2222"
+ [32]=>
+ string(0) ""
+ [33]=>
+ string(0) ""
+ [34]=>
+ string(0) ""
+ [35]=>
+ string(0) ""
+ [36]=>
+ string(0) ""
+ [37]=>
+ string(0) ""
+ [38]=>
+ string(0) ""
+ [39]=>
+ string(0) ""
+ [40]=>
+ string(14) "(123) 555-3333"
+ [41]=>
+ string(0) ""
+ [42]=>
+ string(0) ""
+ [43]=>
+ string(0) ""
+ [44]=>
+ string(0) ""
+ [45]=>
+ string(0) ""
+ [46]=>
+ string(0) ""
+ [47]=>
+ string(0) ""
+ [48]=>
+ string(0) ""
+ [49]=>
+ string(6) "0/0/00"
+ [50]=>
+ string(0) ""
+ [51]=>
+ string(0) ""
+ [52]=>
+ string(6) "0/0/00"
+ [53]=>
+ string(0) ""
+ [54]=>
+ string(11) "Programming"
+ [55]=>
+ string(0) ""
+ [56]=>
+ string(0) ""
+ [57]=>
+ string(16) "john@example.com"
+ [58]=>
+ string(4) "SMTP"
+ [59]=>
+ string(29) "John Smith (john@example.com)"
+ [60]=>
+ string(0) ""
+ [61]=>
+ string(0) ""
+ [62]=>
+ string(0) ""
+ [63]=>
+ string(0) ""
+ [64]=>
+ string(0) ""
+ [65]=>
+ string(0) ""
+ [66]=>
+ string(11) "Unspecified"
+ [67]=>
+ string(0) ""
+ [68]=>
+ string(0) ""
+ [69]=>
+ string(0) ""
+ [70]=>
+ string(4) "J.S."
+ [71]=>
+ string(0) ""
+ [72]=>
+ string(0) ""
+ [73]=>
+ string(0) ""
+ [74]=>
+ string(0) ""
+ [75]=>
+ string(0) ""
+ [76]=>
+ string(0) ""
+ [77]=>
+ string(16) "PHP
+Perl
+Python
+"
+ [78]=>
+ string(0) ""
+ [79]=>
+ string(0) ""
+ [80]=>
+ string(0) ""
+ [81]=>
+ string(6) "Normal"
+ [82]=>
+ string(5) "False"
+ [83]=>
+ string(0) ""
+ [84]=>
+ string(0) ""
+ [85]=>
+ string(6) "Normal"
+ [86]=>
+ string(0) ""
+ [87]=>
+ string(0) ""
+ [88]=>
+ string(0) ""
+ [89]=>
+ string(0) ""
+ [90]=>
+ string(0) ""
+ [91]=>
+ string(0) ""
+ }
+}
--- /dev/null
+"Title","First Name","Middle Name","Last Name","Suffix","Company","Department","Job Title","Business Street","Business Street 2","Business Street 3","Business City","Business State","Business Postal Code","Business Country/Region","Home Street","Home Street 2","Home Street 3","Home City","Home State","Home Postal Code","Home Country/Region","Other Street","Other Street 2","Other Street 3","Other City","Other State","Other Postal Code","Other Country/Region","Assistant's Phone","Business Fax","Business Phone","Business Phone 2","Callback","Car Phone","Company Main Phone","Home Fax","Home Phone","Home Phone 2","ISDN","Mobile Phone","Other Fax","Other Phone","Pager","Primary Phone","Radio Phone","TTY/TDD Phone","Telex","Account","Anniversary","Assistant's Name","Billing Information","Birthday","Business Address PO Box","Categories","Children","Directory Server","E-mail Address","E-mail Type","E-mail Display Name","E-mail 2 Address","E-mail 2 Type","E-mail 2 Display Name","E-mail 3 Address","E-mail 3 Type","E-mail 3 Display Name","Gender","Government ID Number","Hobby","Home Address PO Box","Initials","Internet Free Busy","Keywords","Language","Location","Manager's Name","Mileage","Notes","Office Location","Organizational ID Number","Other Address PO Box","Priority","Private","Profession","Referred By","Sensitivity","Spouse","User 1","User 2","User 3","User 4","Web Page"
+"","","","","","","","","Big Tower'"", 1"" Floor
+123 Main Street",,,"","","","","",,,"","","","","",,,"","","","","","","","","","","","","","","","","","","","","","","","","0/0/00","",,"0/0/00",,,,,"","","",,,,,,,"Unspecified","",,,"","","","","","",,,"","",,"Normal","False","",,"Normal","","","","","",""
--- /dev/null
+--TEST--
+Horde_File_Csv: test for Bug #6370
+--FILE--
+<?php
+
+require_once dirname(__FILE__) . '/../../../lib/Horde/Csv.php';
+
+$file = dirname(__FILE__) . '/bug_6370.csv';
+
+// Explicit conf since we can't detect these settings. Might be able
+// to improve auto-detection, but it definitely should work with the
+// settings specified explicitly.
+// var_dump(Horde_File_Csv::discoverFormat($file));
+$conf['crlf'] = "\n";
+$conf['sep'] = ',';
+$conf['fields'] = 92;
+$conf['quote'] = '"';
+
+$csv = array();
+while ($row = Horde_File_Csv::read($file, $conf)) {
+ if (is_a($row, 'PEAR_Error')) {
+ var_dump($row);
+ exit;
+ }
+ $csv[] = $row;
+}
+var_dump($csv);
+$warnings = Horde_File_Csv::warning();
+if (count($warnings)) {
+ var_dump($warnings);
+}
+
+?>
+--EXPECT--
+array(2) {
+ [0]=>
+ array(92) {
+ [0]=>
+ string(5) "Title"
+ [1]=>
+ string(10) "First Name"
+ [2]=>
+ string(11) "Middle Name"
+ [3]=>
+ string(9) "Last Name"
+ [4]=>
+ string(6) "Suffix"
+ [5]=>
+ string(7) "Company"
+ [6]=>
+ string(10) "Department"
+ [7]=>
+ string(9) "Job Title"
+ [8]=>
+ string(15) "Business Street"
+ [9]=>
+ string(17) "Business Street 2"
+ [10]=>
+ string(17) "Business Street 3"
+ [11]=>
+ string(13) "Business City"
+ [12]=>
+ string(14) "Business State"
+ [13]=>
+ string(20) "Business Postal Code"
+ [14]=>
+ string(23) "Business Country/Region"
+ [15]=>
+ string(11) "Home Street"
+ [16]=>
+ string(13) "Home Street 2"
+ [17]=>
+ string(13) "Home Street 3"
+ [18]=>
+ string(9) "Home City"
+ [19]=>
+ string(10) "Home State"
+ [20]=>
+ string(16) "Home Postal Code"
+ [21]=>
+ string(19) "Home Country/Region"
+ [22]=>
+ string(12) "Other Street"
+ [23]=>
+ string(14) "Other Street 2"
+ [24]=>
+ string(14) "Other Street 3"
+ [25]=>
+ string(10) "Other City"
+ [26]=>
+ string(11) "Other State"
+ [27]=>
+ string(17) "Other Postal Code"
+ [28]=>
+ string(20) "Other Country/Region"
+ [29]=>
+ string(17) "Assistant's Phone"
+ [30]=>
+ string(12) "Business Fax"
+ [31]=>
+ string(14) "Business Phone"
+ [32]=>
+ string(16) "Business Phone 2"
+ [33]=>
+ string(8) "Callback"
+ [34]=>
+ string(9) "Car Phone"
+ [35]=>
+ string(18) "Company Main Phone"
+ [36]=>
+ string(8) "Home Fax"
+ [37]=>
+ string(10) "Home Phone"
+ [38]=>
+ string(12) "Home Phone 2"
+ [39]=>
+ string(4) "ISDN"
+ [40]=>
+ string(12) "Mobile Phone"
+ [41]=>
+ string(9) "Other Fax"
+ [42]=>
+ string(11) "Other Phone"
+ [43]=>
+ string(5) "Pager"
+ [44]=>
+ string(13) "Primary Phone"
+ [45]=>
+ string(11) "Radio Phone"
+ [46]=>
+ string(13) "TTY/TDD Phone"
+ [47]=>
+ string(5) "Telex"
+ [48]=>
+ string(7) "Account"
+ [49]=>
+ string(11) "Anniversary"
+ [50]=>
+ string(16) "Assistant's Name"
+ [51]=>
+ string(19) "Billing Information"
+ [52]=>
+ string(8) "Birthday"
+ [53]=>
+ string(23) "Business Address PO Box"
+ [54]=>
+ string(10) "Categories"
+ [55]=>
+ string(8) "Children"
+ [56]=>
+ string(16) "Directory Server"
+ [57]=>
+ string(14) "E-mail Address"
+ [58]=>
+ string(11) "E-mail Type"
+ [59]=>
+ string(19) "E-mail Display Name"
+ [60]=>
+ string(16) "E-mail 2 Address"
+ [61]=>
+ string(13) "E-mail 2 Type"
+ [62]=>
+ string(21) "E-mail 2 Display Name"
+ [63]=>
+ string(16) "E-mail 3 Address"
+ [64]=>
+ string(13) "E-mail 3 Type"
+ [65]=>
+ string(21) "E-mail 3 Display Name"
+ [66]=>
+ string(6) "Gender"
+ [67]=>
+ string(20) "Government ID Number"
+ [68]=>
+ string(5) "Hobby"
+ [69]=>
+ string(19) "Home Address PO Box"
+ [70]=>
+ string(8) "Initials"
+ [71]=>
+ string(18) "Internet Free Busy"
+ [72]=>
+ string(8) "Keywords"
+ [73]=>
+ string(8) "Language"
+ [74]=>
+ string(8) "Location"
+ [75]=>
+ string(14) "Manager's Name"
+ [76]=>
+ string(7) "Mileage"
+ [77]=>
+ string(5) "Notes"
+ [78]=>
+ string(15) "Office Location"
+ [79]=>
+ string(24) "Organizational ID Number"
+ [80]=>
+ string(20) "Other Address PO Box"
+ [81]=>
+ string(8) "Priority"
+ [82]=>
+ string(7) "Private"
+ [83]=>
+ string(10) "Profession"
+ [84]=>
+ string(11) "Referred By"
+ [85]=>
+ string(11) "Sensitivity"
+ [86]=>
+ string(6) "Spouse"
+ [87]=>
+ string(6) "User 1"
+ [88]=>
+ string(6) "User 2"
+ [89]=>
+ string(6) "User 3"
+ [90]=>
+ string(6) "User 4"
+ [91]=>
+ string(8) "Web Page"
+ }
+ [1]=>
+ array(92) {
+ [0]=>
+ string(0) ""
+ [1]=>
+ string(0) ""
+ [2]=>
+ string(0) ""
+ [3]=>
+ string(0) ""
+ [4]=>
+ string(0) ""
+ [5]=>
+ string(0) ""
+ [6]=>
+ string(0) ""
+ [7]=>
+ string(0) ""
+ [8]=>
+ string(37) "Big Tower'", 1" Floor
+123 Main Street"
+ [9]=>
+ string(0) ""
+ [10]=>
+ string(0) ""
+ [11]=>
+ string(0) ""
+ [12]=>
+ string(0) ""
+ [13]=>
+ string(0) ""
+ [14]=>
+ string(0) ""
+ [15]=>
+ string(0) ""
+ [16]=>
+ string(0) ""
+ [17]=>
+ string(0) ""
+ [18]=>
+ string(0) ""
+ [19]=>
+ string(0) ""
+ [20]=>
+ string(0) ""
+ [21]=>
+ string(0) ""
+ [22]=>
+ string(0) ""
+ [23]=>
+ string(0) ""
+ [24]=>
+ string(0) ""
+ [25]=>
+ string(0) ""
+ [26]=>
+ string(0) ""
+ [27]=>
+ string(0) ""
+ [28]=>
+ string(0) ""
+ [29]=>
+ string(0) ""
+ [30]=>
+ string(0) ""
+ [31]=>
+ string(0) ""
+ [32]=>
+ string(0) ""
+ [33]=>
+ string(0) ""
+ [34]=>
+ string(0) ""
+ [35]=>
+ string(0) ""
+ [36]=>
+ string(0) ""
+ [37]=>
+ string(0) ""
+ [38]=>
+ string(0) ""
+ [39]=>
+ string(0) ""
+ [40]=>
+ string(0) ""
+ [41]=>
+ string(0) ""
+ [42]=>
+ string(0) ""
+ [43]=>
+ string(0) ""
+ [44]=>
+ string(0) ""
+ [45]=>
+ string(0) ""
+ [46]=>
+ string(0) ""
+ [47]=>
+ string(0) ""
+ [48]=>
+ string(0) ""
+ [49]=>
+ string(6) "0/0/00"
+ [50]=>
+ string(0) ""
+ [51]=>
+ string(0) ""
+ [52]=>
+ string(6) "0/0/00"
+ [53]=>
+ string(0) ""
+ [54]=>
+ string(0) ""
+ [55]=>
+ string(0) ""
+ [56]=>
+ string(0) ""
+ [57]=>
+ string(0) ""
+ [58]=>
+ string(0) ""
+ [59]=>
+ string(0) ""
+ [60]=>
+ string(0) ""
+ [61]=>
+ string(0) ""
+ [62]=>
+ string(0) ""
+ [63]=>
+ string(0) ""
+ [64]=>
+ string(0) ""
+ [65]=>
+ string(0) ""
+ [66]=>
+ string(11) "Unspecified"
+ [67]=>
+ string(0) ""
+ [68]=>
+ string(0) ""
+ [69]=>
+ string(0) ""
+ [70]=>
+ string(0) ""
+ [71]=>
+ string(0) ""
+ [72]=>
+ string(0) ""
+ [73]=>
+ string(0) ""
+ [74]=>
+ string(0) ""
+ [75]=>
+ string(0) ""
+ [76]=>
+ string(0) ""
+ [77]=>
+ string(1) ""
+ [78]=>
+ string(0) ""
+ [79]=>
+ string(0) ""
+ [80]=>
+ string(0) ""
+ [81]=>
+ string(6) "Normal"
+ [82]=>
+ string(5) "False"
+ [83]=>
+ string(0) ""
+ [84]=>
+ string(0) ""
+ [85]=>
+ string(6) "Normal"
+ [86]=>
+ string(0) ""
+ [87]=>
+ string(0) ""
+ [88]=>
+ string(0) ""
+ [89]=>
+ string(0) ""
+ [90]=>
+ string(0) ""
+ [91]=>
+ string(0) ""
+ }
+}
--- /dev/null
+"Title","First Name","Middle Name","Last Name","Suffix","Company","Department","Job Title","Business Street","Business Street 2","Business Street 3","Business City","Business State","Business Postal Code","Business Country/Region","Home Street","Home Street 2","Home Street 3","Home City","Home State","Home Postal Code","Home Country/Region","Other Street","Other Street 2","Other Street 3","Other City","Other State","Other Postal Code","Other Country/Region","Assistant's Phone","Business Fax","Business Phone","Business Phone 2","Callback","Car Phone","Company Main Phone","Home Fax","Home Phone","Home Phone 2","ISDN","Mobile Phone","Other Fax","Other Phone","Pager","Primary Phone","Radio Phone","TTY/TDD Phone","Telex","Account","Anniversary","Assistant's Name","Billing Information","Birthday","Business Address PO Box","Categories","Children","Directory Server","E-mail Address","E-mail Type","E-mail Display Name","E-mail 2 Address","E-mail 2 Type","E-mail 2 Display Name","E-mail 3 Address","E-mail 3 Type","E-mail 3 Display Name","Gender","Government ID Number","Hobby","Home Address PO Box","Initials","Internet Free Busy","Keywords","Language","Location","Manager's Name","Mileage","Notes","Office Location","Organizational ID Number","Other Address PO Box","Priority","Private","Profession","Referred By","Sensitivity","Spouse","User 1","User 2","User 3","User 4","Web Page"
+"","","","","","","","","123, 12th Floor,
+Main Street",,,"","","","","",,,"","","","","",,,"","","","","","","","","","","","","","","","","","","","","","","","","0/0/00","",,"0/0/00",,"",,,"","","","","","",,,,"Unspecified","",,,"","","","","","",,"
+","","",,"Normal","False","",,"Normal","","","","","",""
--- /dev/null
+--TEST--
+Horde_File_Csv: test for Bug #6372
+--FILE--
+<?php
+
+require_once dirname(__FILE__) . '/../../../lib/Horde/Csv.php';
+
+$file = dirname(__FILE__) . '/bug_6372.csv';
+
+// Explicit conf since we can't detect these settings. Might be able
+// to improve auto-detection, but it definitely should work with the
+// settings specified explicitly.
+// var_dump(Horde_File_Csv::discoverFormat($file));
+$conf['crlf'] = "\n";
+$conf['sep'] = ',';
+$conf['fields'] = 92;
+$conf['quote'] = '"';
+
+$csv = array();
+while ($row = Horde_File_Csv::read($file, $conf)) {
+ if (is_a($row, 'PEAR_Error')) {
+ var_dump($row);
+ exit;
+ }
+ $csv[] = $row;
+}
+var_dump($csv);
+$warnings = Horde_File_Csv::warning();
+if (count($warnings)) {
+ var_dump($warnings);
+}
+
+?>
+--EXPECT--
+array(2) {
+ [0]=>
+ array(92) {
+ [0]=>
+ string(5) "Title"
+ [1]=>
+ string(10) "First Name"
+ [2]=>
+ string(11) "Middle Name"
+ [3]=>
+ string(9) "Last Name"
+ [4]=>
+ string(6) "Suffix"
+ [5]=>
+ string(7) "Company"
+ [6]=>
+ string(10) "Department"
+ [7]=>
+ string(9) "Job Title"
+ [8]=>
+ string(15) "Business Street"
+ [9]=>
+ string(17) "Business Street 2"
+ [10]=>
+ string(17) "Business Street 3"
+ [11]=>
+ string(13) "Business City"
+ [12]=>
+ string(14) "Business State"
+ [13]=>
+ string(20) "Business Postal Code"
+ [14]=>
+ string(23) "Business Country/Region"
+ [15]=>
+ string(11) "Home Street"
+ [16]=>
+ string(13) "Home Street 2"
+ [17]=>
+ string(13) "Home Street 3"
+ [18]=>
+ string(9) "Home City"
+ [19]=>
+ string(10) "Home State"
+ [20]=>
+ string(16) "Home Postal Code"
+ [21]=>
+ string(19) "Home Country/Region"
+ [22]=>
+ string(12) "Other Street"
+ [23]=>
+ string(14) "Other Street 2"
+ [24]=>
+ string(14) "Other Street 3"
+ [25]=>
+ string(10) "Other City"
+ [26]=>
+ string(11) "Other State"
+ [27]=>
+ string(17) "Other Postal Code"
+ [28]=>
+ string(20) "Other Country/Region"
+ [29]=>
+ string(17) "Assistant's Phone"
+ [30]=>
+ string(12) "Business Fax"
+ [31]=>
+ string(14) "Business Phone"
+ [32]=>
+ string(16) "Business Phone 2"
+ [33]=>
+ string(8) "Callback"
+ [34]=>
+ string(9) "Car Phone"
+ [35]=>
+ string(18) "Company Main Phone"
+ [36]=>
+ string(8) "Home Fax"
+ [37]=>
+ string(10) "Home Phone"
+ [38]=>
+ string(12) "Home Phone 2"
+ [39]=>
+ string(4) "ISDN"
+ [40]=>
+ string(12) "Mobile Phone"
+ [41]=>
+ string(9) "Other Fax"
+ [42]=>
+ string(11) "Other Phone"
+ [43]=>
+ string(5) "Pager"
+ [44]=>
+ string(13) "Primary Phone"
+ [45]=>
+ string(11) "Radio Phone"
+ [46]=>
+ string(13) "TTY/TDD Phone"
+ [47]=>
+ string(5) "Telex"
+ [48]=>
+ string(7) "Account"
+ [49]=>
+ string(11) "Anniversary"
+ [50]=>
+ string(16) "Assistant's Name"
+ [51]=>
+ string(19) "Billing Information"
+ [52]=>
+ string(8) "Birthday"
+ [53]=>
+ string(23) "Business Address PO Box"
+ [54]=>
+ string(10) "Categories"
+ [55]=>
+ string(8) "Children"
+ [56]=>
+ string(16) "Directory Server"
+ [57]=>
+ string(14) "E-mail Address"
+ [58]=>
+ string(11) "E-mail Type"
+ [59]=>
+ string(19) "E-mail Display Name"
+ [60]=>
+ string(16) "E-mail 2 Address"
+ [61]=>
+ string(13) "E-mail 2 Type"
+ [62]=>
+ string(21) "E-mail 2 Display Name"
+ [63]=>
+ string(16) "E-mail 3 Address"
+ [64]=>
+ string(13) "E-mail 3 Type"
+ [65]=>
+ string(21) "E-mail 3 Display Name"
+ [66]=>
+ string(6) "Gender"
+ [67]=>
+ string(20) "Government ID Number"
+ [68]=>
+ string(5) "Hobby"
+ [69]=>
+ string(19) "Home Address PO Box"
+ [70]=>
+ string(8) "Initials"
+ [71]=>
+ string(18) "Internet Free Busy"
+ [72]=>
+ string(8) "Keywords"
+ [73]=>
+ string(8) "Language"
+ [74]=>
+ string(8) "Location"
+ [75]=>
+ string(14) "Manager's Name"
+ [76]=>
+ string(7) "Mileage"
+ [77]=>
+ string(5) "Notes"
+ [78]=>
+ string(15) "Office Location"
+ [79]=>
+ string(24) "Organizational ID Number"
+ [80]=>
+ string(20) "Other Address PO Box"
+ [81]=>
+ string(8) "Priority"
+ [82]=>
+ string(7) "Private"
+ [83]=>
+ string(10) "Profession"
+ [84]=>
+ string(11) "Referred By"
+ [85]=>
+ string(11) "Sensitivity"
+ [86]=>
+ string(6) "Spouse"
+ [87]=>
+ string(6) "User 1"
+ [88]=>
+ string(6) "User 2"
+ [89]=>
+ string(6) "User 3"
+ [90]=>
+ string(6) "User 4"
+ [91]=>
+ string(8) "Web Page"
+ }
+ [1]=>
+ array(92) {
+ [0]=>
+ string(0) ""
+ [1]=>
+ string(0) ""
+ [2]=>
+ string(0) ""
+ [3]=>
+ string(0) ""
+ [4]=>
+ string(0) ""
+ [5]=>
+ string(0) ""
+ [6]=>
+ string(0) ""
+ [7]=>
+ string(0) ""
+ [8]=>
+ string(28) "123, 12th Floor,
+Main Street"
+ [9]=>
+ string(0) ""
+ [10]=>
+ string(0) ""
+ [11]=>
+ string(0) ""
+ [12]=>
+ string(0) ""
+ [13]=>
+ string(0) ""
+ [14]=>
+ string(0) ""
+ [15]=>
+ string(0) ""
+ [16]=>
+ string(0) ""
+ [17]=>
+ string(0) ""
+ [18]=>
+ string(0) ""
+ [19]=>
+ string(0) ""
+ [20]=>
+ string(0) ""
+ [21]=>
+ string(0) ""
+ [22]=>
+ string(0) ""
+ [23]=>
+ string(0) ""
+ [24]=>
+ string(0) ""
+ [25]=>
+ string(0) ""
+ [26]=>
+ string(0) ""
+ [27]=>
+ string(0) ""
+ [28]=>
+ string(0) ""
+ [29]=>
+ string(0) ""
+ [30]=>
+ string(0) ""
+ [31]=>
+ string(0) ""
+ [32]=>
+ string(0) ""
+ [33]=>
+ string(0) ""
+ [34]=>
+ string(0) ""
+ [35]=>
+ string(0) ""
+ [36]=>
+ string(0) ""
+ [37]=>
+ string(0) ""
+ [38]=>
+ string(0) ""
+ [39]=>
+ string(0) ""
+ [40]=>
+ string(0) ""
+ [41]=>
+ string(0) ""
+ [42]=>
+ string(0) ""
+ [43]=>
+ string(0) ""
+ [44]=>
+ string(0) ""
+ [45]=>
+ string(0) ""
+ [46]=>
+ string(0) ""
+ [47]=>
+ string(0) ""
+ [48]=>
+ string(0) ""
+ [49]=>
+ string(6) "0/0/00"
+ [50]=>
+ string(0) ""
+ [51]=>
+ string(0) ""
+ [52]=>
+ string(6) "0/0/00"
+ [53]=>
+ string(0) ""
+ [54]=>
+ string(0) ""
+ [55]=>
+ string(0) ""
+ [56]=>
+ string(0) ""
+ [57]=>
+ string(0) ""
+ [58]=>
+ string(0) ""
+ [59]=>
+ string(0) ""
+ [60]=>
+ string(0) ""
+ [61]=>
+ string(0) ""
+ [62]=>
+ string(0) ""
+ [63]=>
+ string(0) ""
+ [64]=>
+ string(0) ""
+ [65]=>
+ string(0) ""
+ [66]=>
+ string(11) "Unspecified"
+ [67]=>
+ string(0) ""
+ [68]=>
+ string(0) ""
+ [69]=>
+ string(0) ""
+ [70]=>
+ string(0) ""
+ [71]=>
+ string(0) ""
+ [72]=>
+ string(0) ""
+ [73]=>
+ string(0) ""
+ [74]=>
+ string(0) ""
+ [75]=>
+ string(0) ""
+ [76]=>
+ string(0) ""
+ [77]=>
+ string(1) "
+"
+ [78]=>
+ string(0) ""
+ [79]=>
+ string(0) ""
+ [80]=>
+ string(0) ""
+ [81]=>
+ string(6) "Normal"
+ [82]=>
+ string(5) "False"
+ [83]=>
+ string(0) ""
+ [84]=>
+ string(0) ""
+ [85]=>
+ string(6) "Normal"
+ [86]=>
+ string(0) ""
+ [87]=>
+ string(0) ""
+ [88]=>
+ string(0) ""
+ [89]=>
+ string(0) ""
+ [90]=>
+ string(0) ""
+ [91]=>
+ string(0) ""
+ }
+}
--- /dev/null
+--TEST--
+Horde_File_Csv: column count tests
+--FILE--
+<?php
+
+require dirname(__FILE__) . '/common.php';
+test_csv('columns1', 'columns2');
+
+?>
+--EXPECT--
+array(4) {
+ [0]=>
+ array(3) {
+ [0]=>
+ string(3) "one"
+ [1]=>
+ string(3) "two"
+ [2]=>
+ string(5) "three"
+ }
+ [1]=>
+ array(3) {
+ [0]=>
+ string(4) "four"
+ [1]=>
+ string(4) "five"
+ [2]=>
+ string(0) ""
+ }
+ [2]=>
+ array(3) {
+ [0]=>
+ string(3) "six"
+ [1]=>
+ string(5) "seven"
+ [2]=>
+ string(5) "eight"
+ }
+ [3]=>
+ array(3) {
+ [0]=>
+ string(4) "nine"
+ [1]=>
+ string(3) "ten"
+ [2]=>
+ string(6) "eleven"
+ }
+}
+array(2) {
+ [0]=>
+ string(54) "Wrong number of fields in line 2. Expected 3, found 2."
+ [1]=>
+ string(48) "More fields found in line 4 than the expected 3."
+}
+array(4) {
+ [0]=>
+ array(3) {
+ [0]=>
+ string(3) "one"
+ [1]=>
+ string(3) "two"
+ [2]=>
+ string(5) "three"
+ }
+ [1]=>
+ array(3) {
+ [0]=>
+ string(4) "four"
+ [1]=>
+ string(4) "five"
+ [2]=>
+ string(0) ""
+ }
+ [2]=>
+ array(3) {
+ [0]=>
+ string(3) "six"
+ [1]=>
+ string(5) "seven"
+ [2]=>
+ string(5) "eight"
+ }
+ [3]=>
+ array(3) {
+ [0]=>
+ string(4) "nine"
+ [1]=>
+ string(3) "ten"
+ [2]=>
+ string(6) "eleven"
+ }
+}
+array(2) {
+ [0]=>
+ string(54) "Wrong number of fields in line 2. Expected 3, found 2."
+ [1]=>
+ string(48) "More fields found in line 4 than the expected 3."
+}
--- /dev/null
+one,two,three
+four,five
+six,seven,eight
+nine,ten,eleven,twelve
--- /dev/null
+"one","two","three"
+"four","five"
+"six","seven","eight"
+"nine","ten","eleven","twelve"
--- /dev/null
+<?php
+/**
+ * @package Horde_File_Csv
+ */
+
+require_once dirname(__FILE__) . '/../../../lib/Horde/Csv.php';
+
+function test_csv()
+{
+ foreach (func_get_args() as $file) {
+ $file = dirname(__FILE__) . '/' . $file . '.csv';
+ try {
+ $conf = Horde_File_Csv::discoverFormat($file);
+ } catch (Horde_File_Csv_Exception $e) {
+ var_dump($conf);
+ return;
+ }
+
+ $csv = array();
+ try {
+ while ($row = Horde_File_Csv::read($file, $conf)) {
+ $csv[] = $row;
+ }
+ } catch (Horde_File_Csv_Exception $e) {
+ var_dump($row);
+ return;
+ }
+
+ var_dump($csv);
+
+ $warnings = Horde_File_Csv::warning();
+ if (count($warnings)) {
+ var_dump($warnings);
+ }
+ }
+}
--- /dev/null
+--TEST--
+Horde_File_Csv: linebreak tests
+--FILE--
+<?php
+
+require dirname(__FILE__) . '/common.php';
+test_csv('simple_cr', 'simple_lf', 'simple_crlf', 'notrailing_lf', 'notrailing_crlf');
+
+?>
+--EXPECT--
+array(2) {
+ [0]=>
+ array(3) {
+ [0]=>
+ string(3) "one"
+ [1]=>
+ string(3) "two"
+ [2]=>
+ string(5) "three"
+ }
+ [1]=>
+ array(3) {
+ [0]=>
+ string(4) "four"
+ [1]=>
+ string(4) "five"
+ [2]=>
+ string(3) "six"
+ }
+}
+array(2) {
+ [0]=>
+ array(3) {
+ [0]=>
+ string(3) "one"
+ [1]=>
+ string(3) "two"
+ [2]=>
+ string(5) "three"
+ }
+ [1]=>
+ array(3) {
+ [0]=>
+ string(4) "four"
+ [1]=>
+ string(4) "five"
+ [2]=>
+ string(3) "six"
+ }
+}
+array(2) {
+ [0]=>
+ array(3) {
+ [0]=>
+ string(3) "one"
+ [1]=>
+ string(3) "two"
+ [2]=>
+ string(5) "three"
+ }
+ [1]=>
+ array(3) {
+ [0]=>
+ string(4) "four"
+ [1]=>
+ string(4) "five"
+ [2]=>
+ string(3) "six"
+ }
+}
+array(2) {
+ [0]=>
+ array(3) {
+ [0]=>
+ string(3) "one"
+ [1]=>
+ string(3) "two"
+ [2]=>
+ string(5) "three"
+ }
+ [1]=>
+ array(3) {
+ [0]=>
+ string(4) "four"
+ [1]=>
+ string(4) "five"
+ [2]=>
+ string(3) "six"
+ }
+}
+array(2) {
+ [0]=>
+ array(3) {
+ [0]=>
+ string(3) "one"
+ [1]=>
+ string(3) "two"
+ [2]=>
+ string(5) "three"
+ }
+ [1]=>
+ array(3) {
+ [0]=>
+ string(4) "four"
+ [1]=>
+ string(4) "five"
+ [2]=>
+ string(3) "six"
+ }
+}
--- /dev/null
+--TEST--
+Horde_File_Csv: multiline tests
+--FILE--
+<?php
+
+require dirname(__FILE__) . '/common.php';
+test_csv('multiline1');
+
+?>
+--EXPECT--
+array(4) {
+ [0]=>
+ array(3) {
+ [0]=>
+ string(3) "one"
+ [1]=>
+ string(3) "two"
+ [2]=>
+ string(10) "three
+four"
+ }
+ [1]=>
+ array(3) {
+ [0]=>
+ string(4) "five"
+ [1]=>
+ string(9) "six
+seven"
+ [2]=>
+ string(5) "eight"
+ }
+ [2]=>
+ array(3) {
+ [0]=>
+ string(4) "nine"
+ [1]=>
+ string(3) "ten"
+ [2]=>
+ string(14) "eleven
+twelve"
+ }
+ [3]=>
+ array(3) {
+ [0]=>
+ string(3) "one"
+ [1]=>
+ string(3) "two"
+ [2]=>
+ string(11) "three
+ four"
+ }
+}
--- /dev/null
+"one","two","three
+four"
+"five","six
+seven","eight"
+"nine","ten","eleven
+twelve"
+"one","two","three
+ four"
--- /dev/null
+one,two,three
+four,five,six
--- /dev/null
+one,two,three
+four,five,six
--- /dev/null
+"one",two,"three"
+four,"five six",seven
--- /dev/null
+"one",two,"three"
+four,"five six",seven
--- /dev/null
+"one two","three, four",five
+six,"seven ",eight
+
--- /dev/null
+"one two","three, four",five
+six,"seven ",eight
+
--- /dev/null
+"one two","three, four","five"
+"six","seven ","eight"
--- /dev/null
+--TEST--
+Horde_File_Csv: quote tests
+--FILE--
+<?php
+
+require dirname(__FILE__) . '/common.php';
+test_csv('quote1', 'quote2', 'quote3', 'quote4', 'quote5');
+
+?>
+--EXPECT--
+array(2) {
+ [0]=>
+ array(3) {
+ [0]=>
+ string(3) "one"
+ [1]=>
+ string(3) "two"
+ [2]=>
+ string(5) "three"
+ }
+ [1]=>
+ array(3) {
+ [0]=>
+ string(4) "four"
+ [1]=>
+ string(8) "five six"
+ [2]=>
+ string(5) "seven"
+ }
+}
+array(2) {
+ [0]=>
+ array(3) {
+ [0]=>
+ string(3) "one"
+ [1]=>
+ string(3) "two"
+ [2]=>
+ string(5) "three"
+ }
+ [1]=>
+ array(3) {
+ [0]=>
+ string(4) "four"
+ [1]=>
+ string(8) "five six"
+ [2]=>
+ string(5) "seven"
+ }
+}
+array(2) {
+ [0]=>
+ array(3) {
+ [0]=>
+ string(7) "one two"
+ [1]=>
+ string(11) "three, four"
+ [2]=>
+ string(4) "five"
+ }
+ [1]=>
+ array(3) {
+ [0]=>
+ string(3) "six"
+ [1]=>
+ string(6) "seven "
+ [2]=>
+ string(5) "eight"
+ }
+}
+array(2) {
+ [0]=>
+ array(3) {
+ [0]=>
+ string(7) "one two"
+ [1]=>
+ string(11) "three, four"
+ [2]=>
+ string(4) "five"
+ }
+ [1]=>
+ array(3) {
+ [0]=>
+ string(3) "six"
+ [1]=>
+ string(6) "seven "
+ [2]=>
+ string(5) "eight"
+ }
+}
+array(2) {
+ [0]=>
+ array(3) {
+ [0]=>
+ string(7) "one two"
+ [1]=>
+ string(11) "three, four"
+ [2]=>
+ string(4) "five"
+ }
+ [1]=>
+ array(3) {
+ [0]=>
+ string(3) "six"
+ [1]=>
+ string(6) "seven "
+ [2]=>
+ string(5) "eight"
+ }
+}
--- /dev/null
+one,two,three\rfour,five,six\r
\ No newline at end of file
--- /dev/null
+one,two,three
+four,five,six
--- /dev/null
+one,two,three
+four,five,six