Muiter
Muiter

Reputation: 1520

CSV output includes unwanted header info

I am using the script below to create *.csv files. The output of lines 5 and 6 are correct. It is also including other information in lines 1-4 and 8-10. This information is from the header and footer of my page.

Any suggestions how to prevent this information from being included?

<?php
$csv_output .= $lang['klant'].';';
$i++;

$csv_output .= $lang['klant_ref'].';';
$i++;

$csv_output .= $lang['pos'].';';
$i++;

$csv_output .= $lang['aantal'].';';
$i++;

$csv_output .= $lang['dikte'].';';
$i++;

$csv_output .= $lang['kwaliteit'].';';
$i++;

$csv_output .= "\n";

for ($j = 0; $j <= $aantal_regels; $j++)
{
    $csv_output .= $klantnaam.';';
    $csv_output .= $klant_ref.';';
    $csv_output .= $posno[$j].';';
    $csv_output .= $aantal[$j].';';
    $csv_output .= $dikte[$j].';';
    $csv_output .= $kwaliteit[$j].';';
    $csv_output .= "\n";
}

$filename = $file;

header("Content-type: application/vnd.ms-excel");
header("Content-disposition: csv" . date("Y-m-d") . ".csv");
header("Content-disposition: filename=".$lang['lijst_dxf']." ".$dossier_nr." ".$klantnaam." ".$klant_ref.".csv");

print $csv_output;
?>

Upvotes: 0

Views: 56

Answers (1)

HamzaNig
HamzaNig

Reputation: 1029

The problem in your $csv_output you need to delete the html content but here quick solution :

...$csv_output =str_replace(array('<link rel="stlesheet" type="text/css" href="includes/css/style.css"></script>','<style typ }</style>',"<div id='wrap'>",'<div class="footer_popup">','<img src="images/torza_logo_t.png"/>','</div></div>')
                    ,array('','','','','',''),$csv_output);
....$filename = $file;

header("Content-type: application/vnd.ms-excel");
header("Content-disposition: csv" . date("Y-m-d") . ".csv");
header("Content-disposition: filename=".$lang['lijst_dxf']." ".$dossier_nr." ".$klantnaam." ".$klant_ref.".csv");

print $csv_output;
?>

Upvotes: 1

Related Questions