Hi there,
I'm trying to read a CSV file. I'm using the following code so that it echo's out what it is reading. Basically, I have a problem that everytime I get it to read the file (which is 14MB in size) it just bottles out and Apache.exe closes. It could handle my test (3KB in size <grin>).
The code I'm using is here:
<?php
// csv.functions.php
// CSV Reader
class parseCSV {
var $dataCSV = array();
function readCSV($filename, $delimeter) {
// Open the file
$file = fopen($filename, "r");
// Read the CSV file 1MB at a time
$getCSV = fgetcsv($file, 1024, $delimeter);
$this->dataCSV = $getCSV;
$fieldsCSV = count($this->dataCSV);
while(($getCSV = fgetcsv($file, 1024, $delimeter))) {
foreach($getCSV as $key => $value) {
echo "Key: ".$key." Value: ".$value."<br>";
if($key == ($fieldsCSV - 1)) {
echo "<br><br>";
}
}
}
// Close the file
fclose($file);
}
}
$parseCSV = new parseCSV;
$readCSV = $parseCSV->readCSV("hotelcsv.txt", ",");
?>
The class looks pointless at present but I intend to use it for a purpose later.
Basically, what is the problem? There isn't anything showing in the log. I'm running PHP 4.2.3 I believe with Apache on Windows.
Thanks in advance,
Chris Evans