I've seen this asked before and I am having trouble getting this to work properly after trying a number of solutions. The problem is I can't get my data to export into a csv format properly. Before I added my ob\_end\_clean it would export out to a csv with html, now it doesn't give me a csv, just text.

Here is my code on the file that is being required.

```
if (isset($_POST["hidden"])) {

$list = array (
    array('aaa', 'bbb', 'ccc', 'dddd'),
    array('123', '456', '789'),
    array('"aaa"', '"bbb"')
);

    $fp = fopen('php://output','w');

    foreach ($list as $row) {
        ob_end_clean();
        fputcsv($fp, $row);
    }

    header('Content-Type: text/csv; charset=utf-8');
    header('Content-Disposition: attachment; filename=data.csv');

}

```

Right now when I do my export, the data gets put back on the screen similar to a var\_dump(). I just simply want this to go to a csv file without having html all over it.