简体   繁体   English

内容类型:text / csv将html输出到csv文件中

[英]Content-type: text/csv output html into the csv file

I can't seem to output only specific information, into a csv or any file. 我似乎无法仅将特定信息输出到csv或任何文件中。 The following, eg, output the html from the page, rather than the data that I'm trying to send to the Applicants.csv: 以下示例,例如,从页面输出html,而不是我尝试发送到Applicants.csv的数据:

(the $a_Lines array has already been populated): ($ a_Lines数组已被填充):

header('Content-type: text/csv');
header('Content-Disposition: attachment; filename="Applicants.csv"');
header('Pragma: no-cache');
header('Expires: 0');

$file = fopen('php://output', 'w');

foreach ( $a_Lines as $row ) {
    fputcsv($file, $row);
}
fclose($file);

Make sure that in expression 确保表达

fputcsv($file, $row);

$row is always array. $ row总是数组。 If you want to create from $a_Lines csv file, then you don't need foreach loop (of course, I presume that $a_Lines is array). 如果要从$ a_Lines csv文件创建,则不需要foreach循环(当然,我认为$ a_Lines是数组)。 In case that you want selected data from $a_Lines array, then run through $a_Lines, create new array or transform existing one and after the loop add prepared array into fputcsv function. 如果要从$ a_Lines数组中选择数据,然后遍历$ a_Lines,创建新数组或转换现有数组,然后在循环后将准备好的数组添加到fputcsv函数中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM