Using the code below, I can successfully pull a single piece of information from a CSV file, detailing a specific row and column i.e C,2.
If I repeat this function on the same page, I get the error message:
"Fatal error: Cannot redeclare get_cell() (previously declared in myphpfile.php:50) in myphpfile.php on line 187"
Is it possible to pick more than one cell from a CSV file using php?
Here's the code:
<?php
function get_cell($cell, $row)
{
$file = 'CSV/mycsvfile.csv';
$row = $row -1;
// Reset the $row if it's negative.
if($row < 0)
{
$row = 0;
}
$handle = fopen ($file, "r");
$counter = 0;
while (($csvline = fgetcsv($handle, 450,",")) != false)
{
if($counter == $row)
{
$new_array = array();
$begin = 'a';
foreach($csvline as $cellnr)
{
$new_array[$begin] = $cellnr;
$begin++;
}
echo $new_array[strtolower($cell)];
}
$counter++;
}
}
get_cell('C', 2);
?>