Skip to content

mmuniraju4444/PHP_Helpers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

PHP_Helpers

#CSVReading.php

Usage :

  • Create Object of CSVReader
 $csv = new CSVReader();
 $csv = new CSVReader("/path/to/csv/file");
  • Get CSV Data
foreach ($csv->setPath("/path/to/csv/file")->getCSVData() as $row) {
    //Process $row here
}
foreach ($csv->getCSVData() as $row) {
    //Process $row here
}
  • Custom Delemiter
$csv->setDelimiter(";");
  • Ignore Header Processing.
$csv->processHeader(false)
  • Set Custom Header
$csv->ignoreFirstRow()->setHeader(["row_1","row_2","row_3"]);

Note : $row is an key => value Array, here key is set as the first row of the CSV file.

Example-1.

row 1 row2 row 3 4
data1 data2 data3

CODE

$csv = new CSVReader();
foreach ($csv->setPath("/tmp/sample.csv")->getCSVData() as $row) {
    print_r($row)
}

OUTPUT

Array (
[row_1] => data1
[row2] => data2
[row_3_4] => data3
)

Example-2.

row 1 row2 row 3 4
data1 data2 data3

CODE

$csv = new CSVReader("/tmp/sample.csv");
foreach ($csv->ignoreFirstRow()->setHeader(["row_1","row_2","row_3"])->getCSVData() as $row) {
    print_r($row)
}

OUTPUT

Array (
[row_1] => data1
[row_2] => data2
[row_3] => data3
)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages