note 124769 added to function.fgetcsv

From: Date: Thu, 27 Feb 2020 15:11:13 +0000
Subject: note 124769 added to function.fgetcsv
Groups: php.notes 
Request: Send a blank email to php-notes+get-214239@lists.php.net to get a copy of this message
In-case anyone is having difficulty working around Byte-order-marks, the following should work. As usual no warranty, you should test your code... It's for UTF-8 only <?php //... $fh = fopen('wut.csv', 'r'); $firstThreeBytes = fread($fh , 3); if($firstThreeBytes !== "\xef\xbb\xbf") { rewind($fh); } while(($row = fgetcsv($fh, 10000, ',')) !== false) { // Your code here } This basically reads 3 bytes and checks if they match https://en.wikipedia.org/wiki/Byte_order_mark has more information if you are dealing with other code-pages ---- Server IP: 45.112.84.4 Probable Submitter: 177.234.144.170 (proxied: 86.24.87.222) ---- Manual Page -- http://php.net/manual/en/function.fgetcsv.php Edit -- https://master.php.net/note/edit/124769 Del: integrated -- https://master.php.net/note/delete/124769/integrated Del: useless -- https://master.php.net/note/delete/124769/useless Del: bad code -- https://master.php.net/note/delete/124769/bad+code Del: spam -- https://master.php.net/note/delete/124769/spam Del: non-english -- https://master.php.net/note/delete/124769/non-english Del: in docs -- https://master.php.net/note/delete/124769/in+docs Del: other reasons-- https://master.php.net/note/delete/124769 Reject -- https://master.php.net/note/reject/124769 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#214239) next »