#46872 [Com]: fgetcsv escape character is misleading

From: Date: Mon, 15 Dec 2008 20:19:53 +0000
Subject: #46872 [Com]: fgetcsv escape character is misleading
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-1636@lists.php.net to get a copy of this message
ID: 46872 Comment by: jordan dot raub at dataxltd dot com Reported By: jordan dot raub at dataxltd dot com Status: Open Bug Type: Documentation problem Operating System: * PHP Version: Irrelevant New Comment: tested w/ php5.3alpha3 and got this... array(2) { [0]=> string(17) "quote \"testing\"" [1]=> string(4) "test" } array(2) { [0]=> string(15) "quote "testing"" [1]=> string(4) "test" } Previous Comments: ------------------------------------------------------------------------ [2008-12-15 19:08:55] jordan dot raub at dataxltd dot com Description: ------------ the documentation is misleading for fgetcsv. \ is not the escape char for 5.2.8 double double quotes ("") will escape a double quote w/in a field. I think the functionality is correct as is, so the docs should just be changed. see http://en.wikipedia.org/wiki/Comma-separated_values Reproduce code: --------------- <?php $fileContents = <<<EOD "quote \"testing\"","" "quote ""testing""","" EOD; $handle = fopen('php://memory', 'w'); fwrite($handle, $fileContents); fseek($handle, 0); while(!feof($handle)) { var_dump(fgetcsv($handle)); } Expected result: ---------------- array(2) { [0]=> string(15) "quote "testing"" [1]=> string(4) "test" } array(2) { [0]=> string(17) "quote ""testing""" [1]=> string(4) "test" } Actual result: -------------- array(2) { [0]=> string(17) "quote \"testing\"" [1]=> string(4) "test" } array(2) { [0]=> string(15) "quote "testing"" [1]=> string(4) "test" } ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=46872&edit=1

« previous php.doc.bugs (#1636) next »