替代fputcsv [英] Alternative to fputcsv

查看:78
本文介绍了替代fputcsv的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要导出到CSV文件的数组,现在我知道有一个fputcsv函数,但是我使用的是PHP 5.0.4版,因此这对我来说不是一个选择.

I have an array that I want to export to a CSV file, now I know that there is a fputcsv function but I am using version 5.0.4 of PHP so this isn't an option for me.

我可以使用另一种方法吗?

Is there an alternative method I can use?

推荐答案

假设您有一个$Data数组,其中包含每个注册表(或行)的单独数组,则可以尝试以下操作:

Assuming you have a $Data array, which contains individual arrays for each registry (or line), you may try this:

$Delimiter = '"';
$Separator = ','
foreach($Data as $Line)
{   
 fwrite($File, $Delimiter.
        implode($Delimiter.$Separator.$Delimiter, $Line).$Delimiter."\n");
}

其中$File是文件的句柄.在$Delimiter中输入要在每个字段周围加上的字符,在$Separator中输入要在各字段之间使用的字符.

Where $File is the handle for your file. Put in $Delimiter, the character you want to put around each field, and in $Separator, the character to use between fields.

这篇关于替代fputcsv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆