Writing a comma to a CSV file with PHP

I am sending the csv file as a header and I want to use a comma (not for separation, just for use). how would i do that? I am using PHP and I cannot use fputcsvit because I am posting it as a header.

+5
source share
2 answers

Just use '"'.$value.'"'around it and everything will be fine.

+10
source

Either write CSV first and then send it through readfileor write it immediately to the output stream:

fputcsv(
    fopen('php://output', 'w+'),
    array(
        'Some text',
        'Some text with commas ,,,,,',
        'Other text'
    )
);

which will then print

"Some text","Some text with commas ,,,,,","Other text"

, fputcsv , , , .

. PHP fopen:

+9

All Articles