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

From: Date: Sat, 11 Aug 2018 13:56:47 +0000
Subject: Bug #76730 [NEW]: fgetcsv don't parse correctly JSON in a cell
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-216717@lists.php.net to get a copy of this message
From: alex at render dot es Operating system: centos 7 PHP version: 7.1.20 Package: *General Issues Bug Type: Bug Bug description:fgetcsv don't parse correctly JSON in a cell 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 bug report at https://bugs.php.net/bug.php?id=76730&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=76730&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=76730&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=76730&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=76730&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=76730&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=76730&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=76730&r=needscript Try newer version: https://bugs.php.net/fix.php?id=76730&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=76730&r=support Expected behavior: https://bugs.php.net/fix.php?id=76730&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=76730&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=76730&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=76730&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=76730&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=76730&r=dst IIS Stability: https://bugs.php.net/fix.php?id=76730&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=76730&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=76730&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=76730&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=76730&r=mysqlcfg

« previous php.bugs (#216717) next »