Adding a newline character within a cell (CSV)

前端 未结 5 822
执笔经年
执笔经年 2020-12-05 12:54

I would like to import product descriptions that need to be logically broken according by things like description, dimensions, finishes etc. How can I insert a line break s

5条回答
  •  醉酒成梦
    2020-12-05 13:29

    I was concatenating the variable and adding multiple items in same row. so below code work for me. "\n" new line code is mandatory to add first and last of each line if you will add it on last only it will append last 1-2 character to new lines.

      $itemCode =  '';
    foreach($returnData['repairdetail'] as $checkkey=>$repairDetailData){
    
        if($checkkey >0){
            $itemCode   .= "\n".trim(@$repairDetailData['ItemMaster']->Item_Code)."\n";
        }else{
            $itemCode   .= "\n".trim(@$repairDetailData['ItemMaster']->Item_Code)."\n";             
        }
        $repairDetaile[]= array(
            $itemCode,
        )
    }
    // pass all array to here 
    foreach ($repairDetaile as $csvData) { 
        fputcsv($csv_file,$csvData,',','"');
    }
    fclose($csv_file);  
    

提交回复
热议问题