I have a CSV file which I am trying to parse into an array using PHP. Here is my code:
<?php
echo "hi";
$csvData = file_get_contents('2.csv');
$lines = explode(PHP_EOL, $csvData);
$array = array();
$x=0;
foreach ($lines as $line) {
$array[] = str_getcsv($line);
$x=$x+1;
}
echo $x;
print_r($array);
echo "<font size=\"10\" color=\"green\">DONE</font>";
?>
When I ran this script I was getting a blank page with no error. So I added and print out statement "hi". So now when I run this script I only get "hi"
I did some troubleshooting and I found out that this line
$array[] = str_getcsv($line);
Specifically the $array[]
is giving me the problem. Here is a link of the script in action