Skip to content

fputcsv incorrectly escapes when quote char is both enclosure and escape char #18348

@vavra

Description

@vavra

Description

The following code:

<?php
fputcsv($fh, ['Jan', 'He said "Hello"', "Line1\nLine2"], ';', '"', '"');

Resulted in this output:

Jan;"He said "Hello"";"Line1
Line2"

But I expected this output instead:

"Jan";"He said ""Hello""";"Line1

In the expected output it should be the quote chars doubled and whole second cell should be by quote chars enclosed. Expected output will be then properly read by Excel (we use Czech, so semicolon used as col separator)

PHP Version

PHP Version 8.4.6
Windows NT ___ 10.0 build 22631 (Windows 11) AMD64

Operating System

Windows

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions