# fputcsv()

- Thread: https://externals.io/message/12090
- Original archive: https://news-web.php.net/php.internals/12090
- Started by David Sklar on 2004-08-11T13:53:11+00:00
- Messages: 8
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #12090 — David Sklar — 2004-08-11T13:53:11+00:00

URL: https://externals.io/message/12090#12090

Attached is my `fputcsv()` patch (and a test case) from April. Could 
someone commit this to 5.1 or 5.0.1?

Thanks,
David

---

## #12093 — Marcus Boerger — 2004-08-11T18:40:07+00:00

URL: https://externals.io/message/12090#12093 · In reply to: #12090

Hello David,

Wednesday, August 11, 2004, 3:53:11 PM, you wrote:

> Attached is my `fputcsv()` patch (and a test case) from April. Could 
> someone commit this to 5.1 or 5.0.1?

That's a new function so it can only go to 5.1. Anyway it's a nice feature.
So if nobody has anything against i'd look into it more detailed later this
week and commit it. Thanks David.

regards
marcus

---

## #12533 — Marcus Boerger — 2004-09-01T21:19:56+00:00

URL: https://externals.io/message/12090#12533 · In reply to: #12093

Hello David,

  as promised i looked at the patch. Besides a small misstake it looks
good. But it seems to work different then `fgetcsv()`. In other words if
you write using `fputcsv()` you are not sure to get the same back with
 `fgetcsv()`. Though my current opinion is that `fputcsv()` is doing it right.
The attached patch includes a testfile that demonstrates the problem.

  anyone having thoughts?

Wednesday, August 11, 2004, 8:40:07 PM, me wrote:

> Hello David,

> Wednesday, August 11, 2004, 3:53:11 PM, you wrote:

> > […]

> That's a new function so it can only go to 5.1. Anyway it's a nice feature.
> So if nobody has anything against i'd look into it more detailed later this
> week and commit it. Thanks David.

> regards
> marcus




-- 
Best regards,
 Marcus                            mailto:helly@php.net

---

## #12546 — David Sklar — 2004-09-02T16:17:51+00:00

URL: https://externals.io/message/12090#12546 · In reply to: #12533

Marcus Boerger wrote:

> Hello David,
> 
>   as promised i looked at the patch. Besides a small misstake it looks
> good. But it seems to work different then `fgetcsv()`. In other words if
> you write using `fputcsv()` you are not sure to get the same back with
> `fgetcsv()`. Though my current opinion is that `fputcsv()` is doing it right.
> The attached patch includes a testfile that demonstrates the problem.
> 
>   anyone having thoughts?

I agree that if you write something with `fputcsv()` and then read it with 
 `fgetcsv()` you should get back what you started with.

I don't see what's broken though. (Maybe I am misunderstanding your test 
cases.) The original array in the test file is:

> +$list = array (
> +  0 => 'aaa,bbb',
> +  1 => 'aaa,"bbb"',
> +  2 => '"aaa","bbb"',
> +  3 => 'aaa,bbb',
> +  4 => '"aaa",bbb',
> +  5 => '"aaa",   "bbb"',
> +  6 => ',',
> +  7 => 'aaa,',
> +  8 => ',"aaa"',
> +  9 => '"",""',
> +  10 => '"""""",',
> +  11 => '""""",aaa',
> +  12 => 'aaa,bbb   ',
> +  13 => 'aaa,"bbb   "',
> +  14 => 'aaa"aaa","bbb"bbb',
> +  15 => 'aaa"aaa""",bbb',
> +  16 => 'aaa,"\\"bbb,ccc',
> +  17 => 'aaa"\\"a","bbb"',
> +  18 => '"\\"","aaa"',
> +  19 => '"\\""",aaa',

And then what gets printed out by `fputcsv()` is this: (which is 
different, but that's OK, since `fputcsv()` has worked its encoding magic):

> +$list = array (
> +  0 => 'aaa,bbb',
> +  1 => 'aaa,"""bbb"""',
> +  2 => '"""aaa""","""bbb"""',
> +  3 => 'aaa,bbb',
> +  4 => '"""aaa""",bbb',
> +  5 => '"""aaa""","   ""bbb"""',
> +  6 => ',',
> +  7 => 'aaa,',
> +  8 => ',"""aaa"""',
> +  9 => '"""""",""""""',
> +  10 => '"""""""""""""",',
> +  11 => '"""""""""""",aaa',
> +  12 => 'aaa,"bbb   "',
> +  13 => 'aaa,"""bbb   """',
> +  14 => '"aaa""aaa""","""bbb""bbb"',
> +  15 => '"aaa""aaa""""""",bbb',
> +  16 => 'aaa,"""\\""bbb",ccc',
> +  17 => '"aaa""\\""a""","""bbb"""',
> +  18 => '"""\\""""","""aaa"""',
> +  19 => '"""\\""""""",aaa',
> +);

And then this is the array after being read in by `fgetcsv()`:

> +$list = array (
> +  0 => 'aaa,bbb',
> +  1 => 'aaa,"bbb"',
> +  2 => '"aaa","bbb"',
> +  3 => 'aaa,bbb',
> +  4 => '"aaa",bbb',
> +  5 => '"aaa",   "bbb"',
> +  6 => ',',
> +  7 => 'aaa,',
> +  8 => ',"aaa"',
> +  9 => '"",""',
> +  10 => '"""""",',
> +  11 => '""""",aaa',
> +  12 => 'aaa,bbb   ',
> +  13 => 'aaa,"bbb   "',
> +  14 => 'aaa"aaa","bbb"bbb',
> +  15 => 'aaa"aaa""",bbb',
> +  16 => 'aaa,"\\"bbb,ccc',
> +  17 => 'aaa"\\"a","bbb"',
> +  18 => '"\\"","aaa"',
> +  19 => '"\\""",aaa',
> +);

Which seems to be the same as the original array?

David

---

## #12549 — Marcus Boerger — 2004-09-02T17:52:11+00:00

URL: https://externals.io/message/12090#12549 · In reply to: #12546

Hello David,

 i looked up the `fputcsv()` magic in the file manually and agree that this
is fairly correct (as i wrote before). But when i execute the test the
second `var_export()` is supposed to show the input from the .phpt file.
Unfortunatley i get a FAIL from run-tests.php:

FAIL various `fputcsv()` functionality tests [ext/standard/tests/file/fputcsv.phpt]
040+   16 => 'aaa,"\\"bbb",ccc',
041+   17 => 'aaa"\\"a""","bbb"',
042+   18 => '"\\""","aaa"""',
043+   19 => '"\\"""",aaa
044+ ',
040-   16 => 'aaa,"\\"bbb,ccc',
041-   17 => 'aaa"\\"a","bbb"',
042-   18 => '"\\"","aaa"',
043-   19 => '"\\""",aaa',marcus@frodo /usr/src/php-cvs $

Care to look into this (done with current HEAD)?

best regards
marcus

Thursday, September 2, 2004, 6:17:51 PM, you wrote:

> Marcus Boerger wrote:

> > […]

> I agree that if you write something with `fputcsv()` and then read it with 
> `fgetcsv()` you should get back what you started with.

> I don't see what's broken though. (Maybe I am misunderstanding your test 
> cases.) The original array in the test file is:

> > […]

> And then what gets printed out by `fputcsv()` is this: (which is 
> different, but that's OK, since `fputcsv()` has worked its encoding magic):

> > […]

> And then this is the array after being read in by `fgetcsv()`:

> > […]

> Which seems to be the same as the original array?

> David




-- 
Best regards,
 Marcus                            mailto:helly@php.net

---

## #12552 — David Sklar — 2004-09-02T20:26:18+00:00

URL: https://externals.io/message/12090#12552 · In reply to: #12549

Marcus Boerger wrote:

> Hello David,
> 
>  i looked up the `fputcsv()` magic in the file manually and agree that this
> is fairly correct (as i wrote before). But when i execute the test the
> second `var_export()` is supposed to show the input from the .phpt file.
> Unfortunatley i get a FAIL from run-tests.php:
> 
> FAIL various `fputcsv()` functionality tests [ext/standard/tests/file/fputcsv.phpt]
> 040+   16 => 'aaa,"\\"bbb",ccc',
> 041+   17 => 'aaa"\\"a""","bbb"',
> 042+   18 => '"\\""","aaa"""',
> 043+   19 => '"\\"""",aaa
> 044+ ',
> 040-   16 => 'aaa,"\\"bbb,ccc',
> 041-   17 => 'aaa"\\"a","bbb"',
> 042-   18 => '"\\"","aaa"',
> 043-   19 => '"\\""",aaa',marcus@frodo /usr/src/php-cvs $
> 
> Care to look into this (done with current HEAD)?

I will poke about in the guts of fgetcsv and see what I can find. There 
have been some changes to `fgetcsv()` in the PHP_4_3 branch, perhaps they 
will fix things.

David

---

## #12553 — Curt Zirzow — 2004-09-03T02:39:11+00:00

URL: https://externals.io/message/12090#12553 · In reply to: #12533

* Thus wrote Marcus Boerger:
> Hello David,
> 
>   as promised i looked at the patch. Besides a small misstake it looks
> good. But it seems to work different then `fgetcsv()`. In other words if
> you write using `fputcsv()` you are not sure to get the same back with
> `fgetcsv()`. Though my current opinion is that `fputcsv()` is doing it right.
> The attached patch includes a testfile that demonstrates the problem.
> 
>   anyone having thoughts?

i remember seeing something a while back when I first looked at
writing this function that low ascii (<32) and higher (>97) ascii chars
constitute a quoted entry.

Unfortuantely I cant refind any of the resources that suggested this
behaviour. I'm just throwing this out in case anyone can confirm
this.


Curt
-- 
First, let me assure you that this is not one of those shady pyramid schemes
you've been hearing about.  No, sir.  Our model is the trapezoid!

---

## #12555 — Marcus Boerger — 2004-09-03T06:28:49+00:00

URL: https://externals.io/message/12090#12555 · In reply to: #12552

Hello David,

  it is obviously `fgetcsv()`, see last comment on
  #29719 [Opn]: fgetcsv - double quotes issue

marcus

Thursday, September 2, 2004, 10:26:18 PM, you wrote:

> Marcus Boerger wrote:

> > […]

> I will poke about in the guts of fgetcsv and see what I can find. There 
> have been some changes to `fgetcsv()` in the PHP_4_3 branch, perhaps they 
> will fix things.
