PHP头文件,csv可下载输出生成错误(输出附加未知的新行字符),zend


PHP header , csv downloadable error in generating output (unknown new lines character is appending with output), zend

用户使用以下代码从数据库下载信息(csv格式)。但是,在获得输出很多行是空白的,即在我的csv将有两行。但是,当在第一行之后获得csv时,将打印2行空白行。

public generatecsvAction()
{
  $answermodel=new Model_DbTable_Answers();
  header("Content-type: application/octet-stream"); 
  //header('Content-Type: text/csv; charset=utf-8'); // tried this too but still same output
  header("Content-Disposition: attachment; filename=exportevent.csv");  
  header("Pragma: no-cache");  
  header("Expires: 0");  
  echo "First_Name,Last_Name,Roll_No1,User_name,col1,col2,col3..... 'n"; // checked without this 'n 
  foreach($testarray as $i) 
  {
    $ans = $answermodel->getanswers1($a,$i);
    if(count($ans)==10) // if user answered all the qustions ,
    {
      //echo "1,";
      foreach($ans as $value)
      {   
        $res=$answermsamodel->findansweroption($value);
        $res=$res.",";
        $s=$s.$res;
      }
      echo $s;
      break;
    }
  }
}

最有可能的是,$answermsamodel->findansweroption($value)返回一个包含换行符的值