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

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

问题描述

当我使用 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始终使用机箱(默认为)字符来封闭列? / p>

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('\n') ||
  FPUTCSV_FLD_CHK('\r') ||
  FPUTCSV_FLD_CHK('\t') ||
  FPUTCSV_FLD_CHK(' ')
)

没有always enclose选项。

There is no "always enclose" option.

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

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