mycow Posted February 19, 2009 Share Posted February 19, 2009 Hello I have the following code and i am trying to find a way to read the file from the 3rd line and not from the first. Is this possible? $handle = fopen("file.csv", 'r'); while(($data = fgetcsv($handle, 100000, ";")) !== false) { list($col1, $col2, $col3, $col4) = $data; } fclose($handle); Thank you for any help Link to comment https://forums.phpfreaks.com/topic/145930-solved-fopen-and-read-file-from-3rd-line/ Share on other sites More sharing options...
omfgthezerg Posted February 19, 2009 Share Posted February 19, 2009 use file, it returns an array for each line. www.php.net/file Link to comment https://forums.phpfreaks.com/topic/145930-solved-fopen-and-read-file-from-3rd-line/#findComment-766109 Share on other sites More sharing options...
mycow Posted February 19, 2009 Author Share Posted February 19, 2009 I forgot to tell you.. the csv is kind of big Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 299 bytes) in C:\xampp\htdocs\crm\test\test.php on line 21 Link to comment https://forums.phpfreaks.com/topic/145930-solved-fopen-and-read-file-from-3rd-line/#findComment-766112 Share on other sites More sharing options...
omfgthezerg Posted February 19, 2009 Share Posted February 19, 2009 ini_set('memory_limit', '52M'); unset your array after. Link to comment https://forums.phpfreaks.com/topic/145930-solved-fopen-and-read-file-from-3rd-line/#findComment-766117 Share on other sites More sharing options...
sasa Posted February 19, 2009 Share Posted February 19, 2009 $handle = fopen("file.csv", 'r'); for($i=0; $i<2; $i++) $data = fgetcsv($handle, 100000, ";"); // read two rows while(($data = fgetcsv($handle, 100000, ";")) !== false) { list($col1, $col2, $col3, $col4) = $data; } fclose($handle); Link to comment https://forums.phpfreaks.com/topic/145930-solved-fopen-and-read-file-from-3rd-line/#findComment-766121 Share on other sites More sharing options...
mycow Posted February 19, 2009 Author Share Posted February 19, 2009 omfgthezerg thanks the code worked. Is there a way to force the reading of the file with a specific encoding? Sasa thank you too for the code. Link to comment https://forums.phpfreaks.com/topic/145930-solved-fopen-and-read-file-from-3rd-line/#findComment-766125 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.