Generate csv file in php -
i trying generate csv file php array containing data. able generate csv file without issue. little struggling heading of file.
here codes.
public function download_csv_file (){ $total_call_log=get_overage_report(); $start_date=date("y-m-01"); $end_date=date("y-m-d"); $filename="overagesreport-$end_date"; $heading="bill period :$start_date $end_date\n"; $csv_output=$heading; $line = "comp_id,companyname,cust_name,plan_type,plan_limit,plan_cost,plan_overage,total_usages,total_overage_cost\n"; $csv_output .= $line; $comma = ","; foreach ($total_call_log $call_info) { $line1 = null; $line1 .= $call_info['comp_id']; $line1 .= $comma.'"'.$call_info['companyname'].'"'; $line1 .= $comma.'"'.$call_info['cust_name'].'"'; $line1 .= $comma.'"'.$call_info['plan_type'].'"'; $line1 .= $comma.'"'.$call_info['plan_limit'].'"'; $line1 .= $comma.'"'.$call_info['plan_cost'].'"'; $line1 .= $comma.'"'.$call_info['plan_overage'].'"'; $line1 .= $comma.'"'.$call_info['total_call_length'].'"'; $line1 .= $comma.'"'.ceil($call_info['total_overage_cost']).'"'; $csv_output .= $line1."\n"; } header('content-type: application/octet-stream'); header("content-disposition: attachment; filename=".$filename.".csv"); print($csv_output); } what want is, in first row column should merge, , heading should there in middle of row. currently, heading($heading) coming in first column only. how can accomplish this????
php csv
No comments:
Post a Comment