note 126088 added to function.fgets

From: Date: Wed, 19 May 2021 11:57:55 +0000
Subject: note 126088 added to function.fgets
Groups: php.notes 
Request: Send a blank email to php-notes+get-216397@lists.php.net to get a copy of this message
Opening huge file can be done using fgetcsv for the current line of a simple fopen, which is already cut the file by lines. Here we add a diliminter min and max to open parts 1,2,3 of ranges of lines : //$f=file, $s=splitter of columns, $n=part, $=number of lines, $m=max number of chars for each line (faster when used) function bigcsv($f,$s,$n,$l,$m=false){ $h=fopen($f,'r'); $r=[]; $i=0; $a=$l*$n; $b=$a+$l; while(!feof($h) && $i>=$a && $i<$b){$r[]=fgetcsv($h,$m,$s); $i++;} fclose($h); return $r;} //split by 1000 lines, with 300 chars max by lines $r1=bigcsv('huge.csv','|',1,1000,300); $r2=bigcsv('huge.csv','|',2,1000,300); ---- Server IP: 45.112.84.4 Probable Submitter: 45.112.85.242 (proxied: 213.245.49.86) ---- Manual Page -- https://php.net/manual/en/function.fgets.php Edit -- https://main.php.net/note/edit/126088 Del: integrated -- https://main.php.net/note/delete/126088/integrated Del: useless -- https://main.php.net/note/delete/126088/useless Del: bad code -- https://main.php.net/note/delete/126088/bad+code Del: spam -- https://main.php.net/note/delete/126088/spam Del: non-english -- https://main.php.net/note/delete/126088/non-english Del: in docs -- https://main.php.net/note/delete/126088/in+docs Del: other reasons-- https://main.php.net/note/delete/126088 Reject -- https://main.php.net/note/reject/126088 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#216397) next »