本文介绍了在 PHP 中将 CSV 写入没有附件的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有本机函数或实体类/库用于在没有附件的 CSV 文件中将数组作为一行写入?如果没有为外壳参数传入任何内容,fputcsv 将默认为 ".谷歌让我失望(返回关于 fputcsv),而 PEAR 的库与 fputcsv 或多或少做了相同的事情.

Is there a native function or solid class/library for writing an array as a line in a CSV file without enclosures? fputcsv will default to " if nothing is passed in for the enclosure param. Google is failing me (returning results for a whole bunch of pages about fputcsv), and PEAR's libraries do more or less the same things as fputcsv.

fputcsv 完全一样的东西,但允许字段保持不加引号.

Something that works exactly like fputcsv, but will allow the fields to remain unquoted.

当前:"field 1","field 2",field3hasNoSpaces

期望:field 1,field 2,field3hasNoSpaces

推荐答案

关于上述附件的警告是有效的,但您已经说过它们不适用于您的用例.

The warnings about foregoing enclosures are valid, but you've said they don't apply to your use-case.

我想知道为什么你不能只使用这样的东西?

I'm wondering why you can't just use something like this?

<?php
$fields = array(
    "field 1","field 2","field3hasNoSpaces"
);
fputs(STDOUT, implode(',', $fields)."
");

这篇关于在 PHP 中将 CSV 写入没有附件的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 21:17