你好朋友我的文字数组用逗号选择了双击,但是当我在csv中按下逗号分隔值转换为两个标题时,请你帮我解决这个问题。
请找到下面的字符串。 例如:我需要"西南,伦敦&支持Office L1"在一个colume
$datestr ='First Name,Last Name,Company,Type,Email,Attendance Status,Invited By,Payroll No,Pharmacy No,Pharmacy Name,RM,RSM,Accomodation Friday,Accomodation Saturday,Job_Title,"Business Partner Session","Awards Evening","North & Central L1","North & Central L2","South East L1","South East & Warehouse L2","South West, London & Support Office L1","South West, London and Support Office L2';
$sessstr = "First Name,"."Last Name,"."Company,"."Type,"."Email,"."Attendance Status,"."Invited By,"."Payroll No,"."Pharmacy No,"."Pharmacy Name,"."RM,"."RSM,"."Accomodation Friday,"."Accomodation Saturday,"."Job_Title,";
$datestr = "Jaikishan, Keswani,Day Lewis,jaikishan.keswani@daylewisplc.co.uk,Yes,Colin,,,1,,,,Yes,Yes,PHP Developer,";
foreach($sessions as $k=>$ses){
$sessstr .= '"'.$ses['session_name'].'",';
$datestr .= 'Yes,';
}
$datestr = substr($datestr,0,-1);
$sessstr = substr($sessstr,0,-1);
$sessstr = $sessstr.",European Welcome Dinner,"."Accommodation By Invitation Letter,"."Notes,"."Awards Evening Food Option,"."Dietary Requirements";
$datestr = $datestr.",,,,,";
header('Content-Type: application/excel');
header('Content-Disposition: attachment; filename="sample.csv"');
$data = array(
$sessstr,
$datestr
);
$fp = fopen('php://output', 'w');
foreach ( $data as $line ) {
$val = explode(",", $line);
fputcsv($fp, $val);
}
fclose($fp);
答案 0 :(得分:0)
如果你正在使用PHP的CSV函数,你应该将数据放在数组中:
$datestr =['First Name','Last Name','Company','Type','Email','Attendance Status','Invited By','Payroll No','Pharmacy No','Pharmacy Name','RM','RSM','Accomodation Friday','Accomodation Saturday','Job_Title','Business Partner Session',"Awards Evening","North & Central L1","North & Central L2","South East L1","South East & Warehouse L2","South West, London & Support Office L1","South West, London and Support Office L2"];
$sessstr = ["First Name","Last Name","Company","Type","Email","Attendance Status","Invited By","Payroll No","Pharmacy No","Pharmacy Name","RM","RSM","Accomodation Friday","Accomodation Saturday","Job_Title" ];
$datestr = ["Jaikishan", "Keswani","Day Lewis","jaikishan.keswani@daylewisplc.co.uk","Yes","Colin","","","1","","","","Yes","Yes","PHP Developer"];
foreach($sessions as $k=>$ses){
$sessstr[] = $ses['session_name'];
$datestr[] = 'Yes';
}
//$datestr = substr($datestr,0,-1);
//$sessstr = substr($sessstr,0,-1);
$sessstr = array_merge($sessstr,["European Welcome Dinner","Accommodation By Invitation Letter","Notes","Awards Evening Food Option","Dietary Requirements" ];
$datestr = array_merge($datestr,[ "","","","","","" ]);
header('Content-Type: application/excel');
header('Content-Disposition: attachment; filename="sample.csv"');
$data = array(
$sessstr,
$datestr
);
$fp = fopen('php://output', 'w');
foreach ( $data as $line ) {
fputcsv($fp, $val);
}
fclose($fp);