我正在尝试将现有CSV文件的内容转换为另一个CSV并下载,但目前它没有正确地将数据写入现有的CSV文件
我的代码:
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"report.csv\"");
$f_pointer=fopen("result.csv","r"); // file pointer
while(!feof($f_pointer)) {
$data=fgetcsv($f_pointer);
echo $data;
}
返回的内容:
> > <br /> <font size='1'><table class='xdebug-error xe-notice' dir='ltr' border='1' cellspacing='0' cellpadding='1'> <tr><th
> align='left' bgcolor='#f57900' colspan="5"><span
> style='background-color: #cc0000; color: #fce94f; font-size:
> x-large;'>( ! )</span> Notice: Array to string conversion in
> C:\xampp\htdocs\162\dld1.php on line <i>9</i></th></tr> <tr><th
> align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
> <tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left'
> bgcolor='#eeeeec'>Time</th><th align='left'
> bgcolor='#eeeeec'>Memory</th><th align='left'
> bgcolor='#eeeeec'>Function</th><th align='left'
> bgcolor='#eeeeec'>Location</th></tr> <tr><td bgcolor='#eeeeec'
> align='center'>1</td><td bgcolor='#eeeeec'
> align='center'>0.0000</td><td bgcolor='#eeeeec'
> align='right'>135152</td><td bgcolor='#eeeeec'>{main}( )</td><td
> title='C:\xampp\htdocs\162\dld1.php'
> bgcolor='#eeeeec'>..\dld1.php<b>:</b>0</td></tr> </table></font>
我希望返回:
17 testproject TDD 1 2 27 10/13/2014 10:19 10/2/2014 7:25 Win7 Windows Desktop Firefox 33
17 testproject DTD 1 2 27 10/13/2014 10:19 10/2/2014 7:25 Win7 Windows Desktop Firefox 33
我的CSV文件:
tID tname accountname accountid status imprcount earliest_imp recent_imp platform device browser browser_version
17 testproject TDD 1 2 27 10/13/2014 10:19 10/2/2014 7:25 Win7 Windows Desktop Firefox 33
17 testproject DTD 1 2 27 10/13/2014 10:19 10/2/2014 7:25 Win7 Windows Desktop Firefox 33
答案 0 :(得分:0)
更改
echo $data;
到
var_dump($data);
问题是由fgetcsv()引起的,因为它返回一个数组而不是字符串