php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #49966 fputcsv does not respect trailing zeros in number-like strings
Submitted: 2009-10-23 09:58 UTC Modified: 2009-10-23 10:48 UTC
From: shankao at gmail dot com Assigned:
Status: Not a bug Package: Filesystem function related
PHP Version: 5.3.1RC2 OS: Centos 5
Private report: No CVE-ID: None
 [2009-10-23 09:58 UTC] shankao at gmail dot com
Description:
------------
You can get into problems with number-like strings. 

For example, phones with trailing zeros 056033023 don't get quoted in the generated csv file. So, a workaround for that could be add an extra space character before the real value.

Reproduce code:
---------------
---
From manual page: function.fputcsv
---
$csv_data = array();
$csv_data[] = '021323123';   // Includes trailing zeros
fputcsv ($fd, $csv_data);


Expected result:
----------------
Phone field keeps trailing zeros

Actual result:
--------------
Phone field gets zeros removed cause interpreted as integer instead of string

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-10-23 10:48 UTC] jani@php.net
The CSV definition does not require all values to be enclosed in quoting char. PHP only does so when needed. But it isn't an AI that can figure out when you might or might not want them to be quoted.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 11:01:30 2024 UTC