PHP code example of econic / csvreader

1. Go to this page and download the library: Download econic/csvreader library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

econic / csvreader example snippets


$CsvReader = new \Econic\CsvReader\Reader();

$array = $CsvReader->setSource("Elephant,421,86\nMouse,15,4")->parse();

array(
	0 => array(
		0 => "Elephant"
		1 => 421
		2 => 86
	),
	1 => array(
		0 => "Mouse"
		1 => 15
		2 => 4
	)
)

foreach ($result as $line) {
	echo "A " . $line[0] . " can become " . $line[1] . "cm tall and " . $line[2] . " years old.";
}

foreach ($result as $line) {
	echo "A " . $line["title"] . " can become " . $line["size"] . "cm tall and " . $line["age"] . " years old.";
}

$CsvReader->setMyFancyOption($value);

$CsvReader->setOption1($value1)->setOption2($value2)->setOption3...

$CsvReader->setSource("1,2,3\n4,5,6");

$CsvReader->setDelimiter(";");

$CsvReader->setNewline("-");

$CsvReader->setEnclosure("'");

$CsvReader->setEscape("!");

$CsvReader->setTrim(false);

$CsvReader->setKey(0, "title");

$CsvReader->addKeys( array( 0 => "title", 1 => "size" ) );

$CsvReader->resetKeys();

$CsvReader->addModifier(0, function($var){
	return strtoupper(str_replace("-", "", $var));
});

$CsvReader->addModifier("title", function($var){
	return str_replace("-", "", $var);
})->addModifier("title", function($var){
	return strtoupper($var);
});

$CsvReader->resetModifiers();

$CsvReader->resetModifiers("title");