php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #12486 fgetcsv - Why not a getcsv (string not file) version?
Submitted: 2001-07-31 09:08 UTC Modified: 2008-11-12 13:03 UTC
Votes:11
Avg. Score:4.3 ± 1.0
Reproduced:11 of 11 (100.0%)
Same Version:3 (27.3%)
Same OS:7 (63.6%)
From: george at whiffen dot net Assigned: hholzgra (profile)
Status: Closed Package: Feature/Change Request
PHP Version: 4.0.6 OS: All
Private report: No CVE-ID: None
 [2001-07-31 09:08 UTC] george at whiffen dot net
Feature Request/Design Issue on FGETCSV

getcsv  i..e fgetcsv without the file read would be very useful, fgetcsv as it is isn't much use.

At least two reasons:

1. Line terminator, depending on Mac, PC, Unix origin the line terminator could be \r,\n,\r\n.  This is not too hard to cope with via a fgets and an explode on \r.  But then I can't use fgetcsv to do the parsing since it insists for some bizarre reason, on doing the file read itself. 

This could be solved by an optional line terminator argument to fgetcsv, as long as it's a regular expression, but it's all extra complication for all the default behaviour users.

2. Acquiring the original, unparsed line.  Typically, if a line of an uploaded csv file fails my own validation I want to just chuck the line back via a "rejects" download.  This is easy if I have the original line read in its original format but a pain if I just have the parsed version and have to put back the comma-separation all over again.  I can't even guarantee to return the original line since I don't know if the fields were quoted or not!

Practically this makes fgetcsv useless for me, simply because it does TOO MUCH i.e. it insists on doing the file read rather than just the parsing!

My preferred solution would have just been to have getcsv accepting a
string,  then fgetcsv would be simply coded as  getcsv(fgets($fp...))

As we've got fgetcsv now, I guess we gotta keep it, but can we also have getcsv please!

Many thanks,

George

P.S. On a more general note, I hope we aren't going to start having php following the Microsoft pseudo-intelligent style of trying to bundle too much into each function.   We want tools, not someone else's solutions to what they think our problem is!

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-06-17 13:50 UTC] hholzgra@php.net
i'm about to add csv_join() / csv_explode()
 [2007-09-19 00:22 UTC] no at mail dot com
It is year 2007 and still no getcsv...
 [2008-11-11 23:16 UTC] kalle@php.net
PHP 5.3 and 6.0 has a str_getcsv() function available if thats what you points at
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 00:01:41 2024 UTC