I'm getting this error message...
line 428 has this line of code...
what the code does...
1. reads a csv file
2. if it detects the word 'copyright' it then removes the first 15 lines
... it does this by copying the whole file content then writing the content back to the file but skipping the first 15 lines
the files that i have this issue with are larger size files
the file in question that i'm working with right now is 7.7MB
My questions are...
1. does around 7.7MB sound like a file size that is too large to be handled by php?
2. having searched the issue... other forums say that it is a poor code problem, so do you guys see anything in my code that i can improve?
3. Do you guys think there is a more efficient way for me to achieve what i'm doing?
here is my code in it's entirety...
Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 47 bytes) in /Library/.....php on line 428
line 428 has this line of code...
Code:
$lines = file($Cdir.$file_names[$i]);
what the code does...
1. reads a csv file
2. if it detects the word 'copyright' it then removes the first 15 lines
... it does this by copying the whole file content then writing the content back to the file but skipping the first 15 lines
the files that i have this issue with are larger size files
the file in question that i'm working with right now is 7.7MB
My questions are...
1. does around 7.7MB sound like a file size that is too large to be handled by php?
2. having searched the issue... other forums say that it is a poor code problem, so do you guys see anything in my code that i can improve?
3. Do you guys think there is a more efficient way for me to achieve what i'm doing?
here is my code in it's entirety...
Code:
$X = 15; // Number of lines to remove
$lines ='';
$lines = file($Cdir.$file_names[$i]);
$line_00 = $lines[0];
//$line_SCheader = $lines[15];
$lineID = $lines[7];
//echo '<p>line_00: '.$line_00.'</p>';
//echo '<p>line_SCheader: '.$line_SCheader.'</p>';
//echo '<p>lineID '.$lineID.'</p>';
$dateType = ''; //reset
if (preg_match('#Copyright#is', $lineID)) {
$dateType = 1; // Jul 4, 2010
$lines = array_slice($lines, $X + 0);
$lines = array_merge($lines);
$search00 = array (
'/,$/'
);
$replace00 = array (
''
);
$lines = preg_replace($search00, $replace00, $lines);
// Write to file
$file = fopen($Cdir.$file_names[$i], 'w');
fwrite($file, implode('', $lines));
fclose($file);
}