带制表符分隔符的fputcsv [英] fputcsv with tab delimiter

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

问题描述

我想创建一个带有制表符分隔符的CSV文档.我尝试了很多事情,并在整个Internet上进行了搜索,但是没有一个网站提供有效的解决方案.这是我现在正在使用的脚本,但是它在导出时没有制表符分隔符

I would like to create a CSV document with a tab delimiter. I've tried a lot of things and searched all over the internet but there isn't a single site with a working solutions. This is the script I'm using right now, but it is exporting without a tab delimiter

    $data[] = array("item 1", "item 2");
    $data[] = array("item 3", "item 4");
    $export = fopen("/export/test.csv", "w");
    foreach ($data as $row) {
      fputcsv($export, $row, "\t");
    }
    fclose($export);

我还尝试了其他方法,而不是像 chr(9)那样的 \ t ,但没有任何效果.这个问题有解决方案吗?

I've also tried different other things instead of \t like chr(9) but nothing worked. Any solutions for this problem?

推荐答案

正在寻找相同问题的解决方案.在马克·贝克(Mark Ba​​ker)的评论中看到了解决方案

Was searching for a solution to the same problem. Saw the solution in the comments by Mark Baker

在将任何内容写入文件之前,使用 fwrite($ export,"sep = \ t" .PHP_EOL); .

Use fwrite($export, "sep=\t".PHP_EOL); before writing any contents to the file.

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

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