* name,age,skill * john,13,knows magic * tanaka,8,makes sushi * jose,5,dances salsa *
* * require_once 'File/CSV/DataSource.php'; * * $csv = new File_CSV_DataSource; * $csv->load('my_cool.csv'); * var_export($csv->connect()); * * array ( * 0 => * array ( * 'name' => 'john', * 'age' => '13', * 'skill' => 'knows magic', * ), * 1 => * array ( * 'name' => 'tanaka', * 'age' => '8', * 'skill' => 'makes sushi', * ), * 2 => * array ( * 'name' => 'jose', * 'age' => '5', * 'skill' => 'dances salsa', * ), * ) * *
* $settings = array( * 'delimiter' => ',', * 'eol' => ";", * 'length' => 999999, * 'escape' => '"' * ); *
* * var_export($csv->getHeaders()); * * array ( * 0 => 'name', * 1 => 'age', * 2 => 'skill', * ) * *
* * $csv = new File_CSV_DataSource; * $csv->load('my_cool.csv'); * * if (!$csv->isSymmetric()) { * die('file has headers and rows with different lengths * cannot connect'); * } * * var_export($csv->connect()); * * array ( * 0 => * array ( * 'name' => 'john', * 'age' => '13', * 'skill' => 'knows magic', * ), * 1 => * array ( * 'name' => 'tanaka', * 'age' => '8', * 'skill' => 'makes sushi', * ), * 2 => * array ( * 'name' => 'jose', * 'age' => '5', * 'skill' => 'dances salsa', * ), * ) * *
* * var_export($csv->connect(array('age'))); * * array ( * 0 => * array ( * 'age' => '13', * ), * 1 => * array ( * 'age' => '8', * ), * 2 => * array ( * 'age' => '5', * ), * ) * *
* name,age,skill * john,13,knows magic * tanaka,8,makes sushi * jose,5,dances salsa * niki,6 *
* $csv->load('my_cool.csv'); * var_export($csv->getAsymmetricRows()); *
* * array ( * 0 => * array ( * 0 => 'niki', * 1 => '6', * ), * ) * *
* $csv = new File_CSV_DataSource; * $csv->load('my_cool.csv'); * var_export($csv->getColumn('name')); *
* * array ( * 0 => 'john', * 1 => 'tanaka', * 2 => 'jose', * ) * *
* $csv = new File_CSV_DataSource; * $csv->load('my_cool.csv'); * $headers = $csv->getHeaders(); *
* var_export($csv->hasColumn($headers[0])); // true * var_export($csv->hasColumn('age')); // true * var_export($csv->hasColumn('I dont exist')); // false *
* * * var_export($csv->fillColumn('age', 99)); * true * * var_export($csv->appendColumn('candy_ownership', array(99, 44, 65))); * true * * var_export($csv->appendColumn('import_id', 111111111)); * true * * var_export($csv->connect()); * * array ( * 0 => * array ( * 'name' => 'john', * 'age' => 99, * 'skill' => 'knows magic', * 'candy_ownership' => 99, * 'import_id' => 111111111, * ), * 1 => * array ( * 'name' => 'tanaka', * 'age' => 99, * 'skill' => 'makes sushi', * 'candy_ownership' => 44, * 'import_id' => 111111111, * ), * 2 => * array ( * 'name' => 'jose', * 'age' => 99, * 'skill' => 'dances salsa', * 'candy_ownership' => 65, * 'import_id' => 111111111, * ), * ) * *
* $csv = new File_CSV_DataSource; * $csv->load('my_cool.csv'); * * // if the csv file loads * if ($csv->load('my_cool.csv')) { * * // grab all data within the age column * var_export($csv->getColumn('age')); * * // rename all values in it with the number 99 * var_export($csv->fillColumn('age', 99)); * * // grab all data within the age column * var_export($csv->getColumn('age')); * * // rename each value in a column independently * $data = array(1, 2, 3); * $csv->fillColumn('age', $data); * * var_export($csv->getColumn('age')); * } *
* array ( * 0 => '13', * 1 => '8', * 2 => '5', * ) *
* true *
* array ( * 0 => 99, * 1 => 99, * 2 => 99, * ) *
* array ( * 0 => 1, * 1 => 2, * 2 => 3, * ) *
* require_once 'File/CSV/DataSource.php'; * $csv = new File_CSV_DataSource; * $csv->load('my_cool.csv'); *
* var_export($csv->connect()); *
* array ( * 0 => * array ( * 'name' => 'john', * 'age' => '13', * 'skill' => 'knows magic', * ), * 1 => * array ( * 'name' => 'tanaka', * 'age' => '8', * 'skill' => 'makes sushi', * ), * 2 => * array ( * 'name' => 'jose', * 'age' => '5', * 'skill' => 'dances salsa', * ), * ) *
* var_export($csv->removeColumn('age')); *
* array ( * 0 => * array ( * 'name' => 'john', * 'skill' => 'knows magic', * ), * 1 => * array ( * 'name' => 'tanaka', * 'skill' => 'makes sushi', * ), * 2 => * array ( * 'name' => 'jose', * 'skill' => 'dances salsa', * ), * ) *
* var_export($csv->getCell(1, 2)); *
* 'makes sushi' *
* * $csv = new File_CSV_DataSource; * * // load the csv file * $csv->load('my_cool.csv'); * * // find out if the given coordinate is valid * if($csv->hasCell(1, 1)) { * * // if so grab that cell and dump it * var_export($csv->getCell(1, 1)); // '8' * * // replace the value of that cell * $csv->fillCell(1, 1, 'new value'); // true * * // output the new value of the cell * var_export($csv->getCell(1, 1)); // 'new value' * * } *
* // show the whole row * var_export($csv->getRow(1)); *
* array ( * 0 => 'tanaka', * 1 => 'new value', * 2 => 'makes sushi', * ) *
* $csv = new File_CSV_DataSource; * var_export($csv->load('my_cool.csv')); // true if file is * // loaded *
* var_export($csv->hasCell(99, 3)); // false *
* var_export($csv->hasCell(1, 1)); // true * var_export($csv->getCell(1, 1)); // '8' *
* var_export($csv->getRow(1)); *
* array ( * 0 => 'tanaka', * 1 => '8', * 2 => 'makes sushi', * ) *
* var_export($csv->getRows(array(1, 2))); *
* array ( * 0 => * array ( * 0 => 'tanaka', * 1 => '8', * 2 => 'makes sushi', * ), * 1 => * array ( * 0 => 'jose', * 1 => '5', * 2 => 'dances salsa', * ), * ) *
* var_export($csv->getRows(array(9, 2))); *
* array ( * 0 => * array ( * 0 => 'jose', * 1 => '5', * 2 => 'dances salsa', * ), * ) *
* $csv = new File_CSV_DataSource; * $csv->load('my_cool.csv'); * var_export($csv->countRows()); // returns 3 *
* require_once 'File/CSV/DataSource.php'; * $csv = new File_CSV_DataSource; * $csv->load('my_cool.csv'); * var_export($csv->connect()); *
* * array ( * 0 => * array ( * 'name' => 'john', * 'age' => '13', * 'skill' => 'knows magic', * ), * 1 => * array ( * 'name' => 'tanaka', * 'age' => '8', * 'skill' => 'makes sushi', * ), * 2 => * array ( * 'name' => 'jose', * 'age' => '5', * 'skill' => 'dances salsa', * ), * ) *
* var_export($csv->appendRow(1)); * var_export($csv->appendRow('2')); * var_export($csv->appendRow(array(3, 3, 3))); *
* true * true * true *
* array ( * 0 => * array ( * 'name' => 'john', * 'age' => '13', * 'skill' => 'knows magic', * ), * 1 => * array ( * 'name' => 'tanaka', * 'age' => '8', * 'skill' => 'makes sushi', * ), * 2 => * array ( * 'name' => 'jose', * 'age' => '5', * 'skill' => 'dances salsa', * ), * 3 => * array ( * 'name' => 1, * 'age' => 1, * 'skill' => 1, * ), * 4 => * array ( * 'name' => '2', * 'age' => '2', * 'skill' => '2', * ), * 5 => * array ( * 'name' => 3, * 'age' => 3, * 'skill' => 3, * ), * ) *
* // load the library * require_once 'File/CSV/DataSource.php'; * $csv = new File_CSV_DataSource; * * // load csv file * $csv->load('my_cool.csv'); * * // fill exitent row * var_export($csv->fillRow(1, 'x')); *
* array ( * 0 => * array ( * 'name' => 'john', * 'age' => '13', * 'skill' => 'knows magic', * ), * 1 => * array ( * 'name' => 'x', * 'age' => 'x', * 'skill' => 'x', * ), * 2 => * array ( * 'name' => 'jose', * 'age' => '5', * 'skill' => 'dances salsa', * ), * ) *
* var_export($csv->fillRow(1, array(1, 2, 3))); *
* * array ( * 0 => * array ( * 'name' => 'john', * 'age' => '13', * 'skill' => 'knows magic', * ), * 1 => * array ( * 'name' => 1, * 'age' => 2, * 'skill' => 3, * ), * 2 => * array ( * 'name' => 'jose', * 'age' => '5', * 'skill' => 'dances salsa', * ), * ) *
* array ( * 0 => * array ( * 'name' => 'john', * 'age' => '13', * 'skill' => 'knows magic', * ), * 1 => // THIS ROW EXISTS!!! * array ( * 'name' => 'tanaka', * 'age' => '8', * 'skill' => 'makes sushi', * ), * 2 => * array ( * 'name' => 'jose', * 'age' => '5', * 'skill' => 'dances salsa', * ), * ) *
* var_export($csv->hasRow(1)); * var_export($csv->hasRow(-1)); * var_export($csv->hasRow(9999)); *
* true * false * false *
* var_export($csv->removeRow(1)); *
* array ( * 0 => * array ( * 'name' => 'john', * 'age' => '13', * 'skill' => 'knows magic', * ), * 1 => * array ( * 'name' => 'jose', * 'age' => '5', * 'skill' => 'dances salsa', * ), * ) *
* john,13,knows magic * tanaka,8,makes sushi * jose,5,dances salsa *
* $csv = new File_CSV_DataSource; * if (!$csv->load('my_cool.csv')) { * die('can not load csv file'); * } *
* var_export($csv->getHeaders()); *
* array ( * 0 => 'john', * 1 => '13', * 2 => 'knows magic', * ) *
* $csv->createHeaders('column') *
* array ( * 0 => 'column_1', * 1 => 'column_2', * 2 => 'column_3', * ) *
* * array ( * 0 => * array ( * 'column_1' => 'john', * 'column_2' => '13', * 'column_3' => 'knows magic', * ), * 1 => * array ( * 'column_1' => 'tanaka', * 'column_2' => '8', * 'column_3' => 'makes sushi', * ), * 2 => * array ( * 'column_1' => 'jose', * 'column_2' => '5', * 'column_3' => 'dances salsa', * ), * ) *
* $new_headers = array('a', 'b', 'c'); * var_export($csv->setHeaders($new_headers)); *
* $new_headers = array('a', 'b'); * var_export($csv->setHeaders($new_headers)); *
* false *
* array ( * 0 => * array ( * 'a' => 'name', * 'b' => 'age', * 'c' => 'skill', * ), * 1 => * array ( * 'a' => 'john', * 'b' => '13', * 'c' => 'knows magic', * ), * 2 => * array ( * 'a' => 'tanaka', * 'b' => '8', * 'c' => 'makes sushi', * ), * 3 => * array ( * 'a' => 'jose', * 'b' => '5', * 'c' => 'dances salsa', * ), * ) *