Why is my Content-Length header wrong?

jurrie

New Member
I am trying to find out the exact length of a string using strlen() in php 5.2. The string ($data) contains '\t' and '\n'.\[code\]echo strlen($data);\[/code\]Code:\[code\] // fetch table header $header = ''; while ($fieldData = http://stackoverflow.com/questions/3561596/$result->fetch_field()) { $header .= $fieldData->name ."\t"; } // fetch data each row, store on tabular row data while ($row = $result->fetch_assoc()) { $line = ''; foreach($row as $value){ if(!isset($value) || $value =http://stackoverflow.com/questions/3561596/=""){ $value = "http://stackoverflow.com/t"; }else{ // important to escape any quotes to preserve them in the data. $value = http://stackoverflow.com/questions/3561596/str_replace('"', '""', $value); // needed to encapsulate data in quotes because some data might be multi line. // the good news is that numbers remain numbers in Excel even though quoted. $valuehttp://stackoverflow.com/questions/3561596/= '"' . $value . '"' . "\t"; } $line .= $value; } $data .= trim($line)."\n"; } // this line is needed because returns embedded in the data have "\r" // and this looks like a "box character" in Excel $data = http://stackoverflow.com/questions/3561596/str_replace("\r", "", $data); // Nice to let someone know that the search came up empty. // Otherwise only the column name headers will be output to Excel. if ($data =http://stackoverflow.com/questions/3561596/="") { $data = "http://stackoverflow.com/nno matching records found/n"; } // create table header showing to download a xls (excel) file header("Content-type: application/octet-stream"); header("Content-Disposition: attachment; filename=$export_filename"); header("Cache-Control: public"); header("Content-length: " . strlen($data); // tells file size header("Pragma: no-cache"); header("Expires: 0"); // output data echo $header."\n".$data;\[/code\]This does not return the exact length (its less than the actual length). Please advice.
 
Back
Top