note 126509 added to splfileobject.getcsvcontrol

From: Date: Thu, 14 Oct 2021 17:31:27 +0000
Subject: note 126509 added to splfileobject.getcsvcontrol
Groups: php.notes 
Request: Send a blank email to php-notes+get-217078@lists.php.net to get a copy of this message
Given an absolute path to a CSV or any text file and a list of possible delimiters and assuming lines are up to 4096 characters long, I use <?php function guess_delimiter($file, $delimiters=[',',';']) { $h = fopen($file,'r'); $count = []; foreach ($delimiters as $del) { $count[$del] = 0; while (($bufer = fgets($h, 4096)) !== false) { $count[$del]+=substr_count($bufer, $del); } rewind($h); } fclose($h); return array_search(max($count), $count); } ---- Server IP: 45.112.84.4 Probable Submitter: 45.112.85.242 (proxied: 190.18.41.218) ---- Manual Page -- https://php.net/manual/en/splfileobject.getcsvcontrol.php Edit -- https://main.php.net/note/edit/126509 Del: integrated -- https://main.php.net/note/delete/126509/integrated Del: useless -- https://main.php.net/note/delete/126509/useless Del: bad code -- https://main.php.net/note/delete/126509/bad+code Del: spam -- https://main.php.net/note/delete/126509/spam Del: non-english -- https://main.php.net/note/delete/126509/non-english Del: in docs -- https://main.php.net/note/delete/126509/in+docs Del: other reasons-- https://main.php.net/note/delete/126509 Reject -- https://main.php.net/note/reject/126509 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#217078) next »