For Programmers: Free Programming Magazines  


Home > Archive > PHP Documentation > September 2006 > #38918 [Opn]: fputcsv() fgetcsv() inconsistency odd number trailing backslashes









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author #38918 [Opn]: fputcsv() fgetcsv() inconsistency odd number trailing backslashes
tony2001@php.net

2006-09-25, 7:58 am

ID: 38918
Updated by: tony2001@php.net
Reported By: mike at opendns dot com
Status: Open
-Bug Type: Filesystem function related
+Bug Type: Documentation problem
Operating System: Linux, debian sarge
PHP Version: 5.1.6
New Comment:

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


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

[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
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com