在PHP中将CSV写入文件而不使用机箱 [英] Write CSV To File Without Enclosures In PHP

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

问题描述

有没有本机函数或实体类/库,用于将数组作为一行写入没有框的CSV文件中? fputcsv 将默认为如果没有传递的机箱参数谷歌是失败我关于 fputcsv 的整个页面),并且PEAR的库或多或少地执行与 fputcsv 相同的操作。



fputcsv ,但是允许字段保持不加引号。



目前:字段1,字段2,field3hasNoSpaces



字段1,字段2,字段3hasNoSpaces

解决方案



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

p>

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


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.

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

currently: "field 1","field 2",field3hasNoSpaces

desired: 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, ',')."\n");

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

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