ID:               38918
 Updated by:       [EMAIL PROTECTED]
 Reported By:      mike at opendns dot com
 Status:           Open
 Bug Type:         Documentation problem
 Operating System: Linux, debian sarge
 PHP Version:      5.1.6
 New Comment:

Are you sure this is a documentation problem? RFC 4180 says nothing
about \ characters needing to be escaped, and quotes (") _are_ escaped
properly in fputcsv(). The problem lies with fgetcsv() incorrectly
parsing a single \ at the end of a value (two \'s work, which is
inconsistent at best).


Previous Comments:
------------------------------------------------------------------------

[2006-09-25 12:23:21] [EMAIL PROTECTED]

This is expected since "\" is the escape character.
Reclassified as docu problem - fputcsv() does not escape the data, you
have to do it yourself.

------------------------------------------------------------------------

[2006-09-22 00:03:09] mike at opendns dot com

Description:
------------
If a string you write to a CSV file with fputcsv() ends with an _odd_
number of backslashes, then when you read it back in with fgetcsv(),
it'll miss the delimeter and combine two elements into one.

Reproduce code:
---------------
$tmp_file = '/tmp/csv_f_up.tmp';

$data_to_write = array('string ends with _odd_ number of backslashes
\\\\\\',"and isn't the last element");

echo "data_to_write:\n";
var_dump($data_to_write);

$h_w = fopen($tmp_file, 'w');
fputcsv($h_w, $data_to_write);
fclose($h_w);

$h_r = fopen($tmp_file, 'r');
$data_read_in = fgetcsv($h_r);
fclose($h_r);

echo "data_read_in:\n";
var_dump($data_read_in);

Expected result:
----------------
data_to_write:
array(2) {
  [0]=>
  string(48) "string ends with _odd_ number of backslashes \\\"
  [1]=>
  string(26) "and isn't the last element"
}
data_read_in:
array(2) {
  [0]=>
  string(48) "string ends with _odd_ number of backslashes \\\"
  [1]=>
  string(26) "and isn't the last element"
}
}

Actual result:
--------------
data_to_write:
array(2) {
  [0]=>
  string(48) "string ends with _odd_ number of backslashes \\\"
  [1]=>
  string(26) "and isn't the last element"
}
data_read_in:
array(1) {
  [0]=>
  string(77) "string ends with _odd_ number of backslashes \\\",and
isn't the last element""
}


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=38918&edit=1

Reply via email to