强制 fputcsv 对 *all* 字段使用 Enclosure [英] Forcing fputcsv to Use Enclosure For *all* Fields

查看:29
本文介绍了强制 fputcsv 对 *all* 字段使用 Enclosure的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用 fputcsv 写出一行到打开的文件句柄时,PHP 会添加一个封闭字符到它认为需要它的任何列,但会让其他列没有外壳.

When I use fputcsv to write out a line to an open file handle, PHP will add an enclosing character to any column that it believes needs it, but will leave other columns without the enclosures.

例如,你可能会得到这样的一行

For example, you might end up with a line like this

11,"Bob ",Jenkins,"200 main st. USA ",etc

除了在每个字段的末尾附加一个虚假空格之外,有没有办法强制 fputcsv 始终用外壳(默认为)字符将列括起来?

Short of appending a bogus space to the end of every field, is there any way to force fputcsv to always enclose columns with the enclosure (defaults to a ") character?

推荐答案

不,fputcsv() 只在以下条件下包围字段

No, fputcsv() only encloses the field under the following conditions

/* enclose a field that contains a delimiter, an enclosure character, or a newline */
if (FPUTCSV_FLD_CHK(delimiter) ||
  FPUTCSV_FLD_CHK(enclosure) ||
  FPUTCSV_FLD_CHK(escape_char) ||
  FPUTCSV_FLD_CHK('
') ||
  FPUTCSV_FLD_CHK('
') ||
  FPUTCSV_FLD_CHK('	') ||
  FPUTCSV_FLD_CHK(' ')
)

没有始终包含"选项.

这篇关于强制 fputcsv 对 *all* 字段使用 Enclosure的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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