Bug #76730 [Opn]: fgetcsv don't parse correctly JSON in a cell

From: Date: Sat, 11 Aug 2018 14:20:03 +0000
Subject: Bug #76730 [Opn]: fgetcsv don't parse correctly JSON in a cell
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-216718@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=76730&edit=1 ID: 76730 User updated by: alex at render dot es Reported by: alex at render dot es Summary: fgetcsv don't parse correctly JSON in a cell Status: Open Type: Bug Package: *General Issues -Operating System: centos 7 +Operating System: centos 7, osx 10.13.6, debian 8 PHP Version: 7.1.20 Block user comment: N Private report: N New Comment: add more oses Previous Comments: ------------------------------------------------------------------------ [2018-08-11 13:56:47] alex at render dot es Description: ------------ --- From manual page: http://www.php.net/function.fgetcsv --- fgetcsv don't parse correctly JSON in a cell. When php parse the cell with; csv_delimiter = ; enclosure = " and the csv has a cell with JSON text like: {"test":"this is \"test\""} the fgetcsv parse will done: {"test":"this is \"test\"""} this a bad JSON format and the error come when when you try to make a json_decode() with the result. Test script: --------------- //CSV "{""test"":""this is \""test\""""}" <?php ini_set('auto_detect_line_endings',TRUE); $f = fopen('test.csv', "r"); $csv_array=array(); // , $enclosure $i=0; while (($line = fgetcsv($f, 0, "\"")) !== false) { foreach ($line as $cell) { $final_json = json_decode($cell); var_dump($final_json); } } ?> ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=76730&edit=1

« previous php.bugs (#216718) next »