|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2005-01-18 01:13 UTC] iliaa@php.net
[2005-01-19 01:18 UTC] b_ulrich at t-online dot de
[2005-01-19 03:53 UTC] sniper@php.net
[2005-01-19 19:08 UTC] b_ulrich at t-online dot de
[2005-01-21 00:34 UTC] iliaa@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 22 08:00:02 2025 UTC |
Description: ------------ If a csv field contains something like ...\"...\"... followed by a newline, fgetcsv assumes that the newline is the end of the datarow even it isn't the end of the field. There's no problem if the field only contains text and newlines or only ...\"...\"... If you create a Spreadsheet (2Rows with 3Columns) containing this: <Row 1 Column 1>: R1C1 <Row 1 Column 2>: say \"YES\" to element in next line <Row 1 Column 3>: R1C3 <Row 2 Column 1>: R2C1 <Row 2 Column 2>: something with multilines <Row 2 Column 3>: R2C3 and export this to CSV, you will get: R1C1;"say \""YES\"" to element in next line";R1C3 R2C1;"something with multilines";R2C3 This is correct Standard-CSV. But if you try to read it with fgetcsv you will get a Result containing 3 Rows, the first and the second containing 2 Elements, the third contains 3 Elements. Reproduce code: --------------- <?php $csv_data="R1C1;\"say \\\"\"YES\\\"\" to\nelement in next line\";R1C3\nR2C1;\"something with\nmultilines\";R2C3\n"; $filename = "/tmp/test.csv"; $handle = fopen($filename, "wb"); fwrite($handle, $csv_data,strlen($csv_data)); fclose($handle); $handle = fopen($filename, "rb"); while (($data = fgetcsv($handle,100000,";","\"")) !== FALSE) { $result[]=$data; } // fclose($handle); print_r($result); ?> Expected result: ---------------- Array ( [0] => Array ( [0] => R1C1 [1] => say \"YES\" to element in next line [2] => R1C3 ) [1] => Array ( [0] => R2C1 [1] => something with multilines [2] => R2C3 ) ) Actual result: -------------- Array ( [0] => Array ( [0] => R1C1 [1] => say \"YES\" to ) [1] => Array ( [0] => element in next line" [1] => R1C3 ) [2] => Array ( [0] => R2C1 [1] => something with multilines [2] => R2C3 ) ) Note: There's no Problem, if there is no linebreak in Row1 Column2 and there is also no Problem if you don't have the backslashes in the line.