This is a discussion on CSV problems within the PHP Language forums, part of the PHP Programming Forums category; Here's one for you. I import a CSV file which is then read using fgetcsv(); My problem is that ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Here's one for you.
I import a CSV file which is then read using fgetcsv(); My problem is that if the fields in the CSV file have commas in them, the whole thing bugs out. I am wondering of it is possible to replace these commas in the fields without replacing the CSV structure. Any help greatly appreciated. Regards Richard Grove http://shopbuilder.org - ecommerce systems Become a Shop Builder re-seller: http://www.affiliatewindow.com/affil...ls.php?mid=611 http://www.affiliatewindow.com/a.pl?590 --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.536 / Virus Database: 331 - Release Date: 03/11/2003 |
|
|||
|
In message <3fb8e3c9$0$108$65c69314@mercury.nildram.net>, Richard Grove
<info@[at].invalid> writes >Here's one for you. >I import a CSV file which is then read using fgetcsv(); >My problem is that if the fields in the CSV file have commas in them, the >whole thing bugs out. >I am wondering of it is possible to replace these commas in the fields >without replacing the CSV structure. > In general a CSV format file should have double-quote marks around the field data if it has commas in it. E.g. 1,2,3,some test data,5 1,2,3,"some, test data",5 fgetcsv() should then read this correctly. -- Rob Allen |
|
|||
|
"Richard Grove" <info[at]redeyemedia[dot]co[dot]uk> writes:
> I import a CSV file which is then read using fgetcsv(); > My problem is that if the fields in the CSV file have commas in them, the > whole thing bugs out. What exactly happens when "the whole thing bugs out"? Are the commas in the fields inside quotation marks? Are there quotation marks in the file that could be confusing fgetcsv()? Could you post a line from the CSV file and the code you're using to read it? That way we could see exactly what's happening. > I am wondering of it is possible to replace these commas in the fields > without replacing the CSV structure. Let's get all the facts before looking for a solution. -- Michael Fuhr http://www.fuhr.org/~mfuhr/ |
|
|||
|
"Michael Fuhr" <mfuhr@fuhr.org> wrote in message
news:3fb8f879$1_1@omega.dimensional.com... > "Richard Grove" <info[at]redeyemedia[dot]co[dot]uk> writes: > > > I import a CSV file which is then read using fgetcsv(); > > My problem is that if the fields in the CSV file have commas in them, the > > whole thing bugs out. > > What exactly happens when "the whole thing bugs out"? Are the > commas in the fields inside quotation marks? Are there quotation > marks in the file that could be confusing fgetcsv()? > > Could you post a line from the CSV file and the code you're using > to read it? That way we could see exactly what's happening. > > > I am wondering of it is possible to replace these commas in the fields > > without replacing the CSV structure. > > Let's get all the facts before looking for a solution. > > -- > Michael Fuhr > http://www.fuhr.org/~mfuhr/ My CSV file doesn't have quotes. When it bugs out, what I meant to say was that when it populates the databse, it skips columns and puts values in the wrong place. Not really bugging out I suppose. Regards Richard Grove 01892 546979 http://shopbuilder.org - ecommerce systems Become a Shop Builder re-seller: http://www.affiliatewindow.com/affil...ls.php?mid=611 http://www.affiliatewindow.com/a.pl?590 --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.536 / Virus Database: 331 - Release Date: 03/11/2003 |
|
|||
|
"Richard Grove" <info[at]redeyemedia[dot]co[dot]uk> writes:
> "Michael Fuhr" <mfuhr@fuhr.org> wrote in message > news:3fb8f879$1_1@omega.dimensional.com... > > "Richard Grove" <info[at]redeyemedia[dot]co[dot]uk> writes: > > > > > I import a CSV file which is then read using fgetcsv(); > > > My problem is that if the fields in the CSV file have commas in them, > the > > > whole thing bugs out. > > > > What exactly happens when "the whole thing bugs out"? Are the > > commas in the fields inside quotation marks? Are there quotation > > marks in the file that could be confusing fgetcsv()? > > > > Could you post a line from the CSV file and the code you're using > > to read it? That way we could see exactly what's happening. > > My CSV file doesn't have quotes. If a comma is the field separater, and if a field's value contains commas, then that field needs to be quoted. Without some way to distinguish which commas are part of a field and which commas separate different fields, you'll get unexpected results. > When it bugs out, what I meant to say was that when it populates the > databse, it skips columns and puts values in the wrong place. > Not really bugging out I suppose. Make sure you're reading the data correctly before worrying about how it's inserted into a database. As I asked before, please post a troublesome line from the CSV file and the code you're using to read it. If we can see what you're doing then we might be able to offer advice on how to fix the problem. -- Michael Fuhr http://www.fuhr.org/~mfuhr/ |
|
|||
|
"Richard Grove" <info[at]redeyemedia[dot]co[dot]uk> wrote in message
news:3fb8fe02$0$119$65c69314@mercury.nildram.net.. . > "Michael Fuhr" <mfuhr@fuhr.org> wrote in message > news:3fb8f879$1_1@omega.dimensional.com... > > "Richard Grove" <info[at]redeyemedia[dot]co[dot]uk> writes: > > > > > I import a CSV file which is then read using fgetcsv(); > > > My problem is that if the fields in the CSV file have commas in them, > the > > > whole thing bugs out. > > > > What exactly happens when "the whole thing bugs out"? Are the > > commas in the fields inside quotation marks? Are there quotation > > marks in the file that could be confusing fgetcsv()? > > > > Could you post a line from the CSV file and the code you're using > > to read it? That way we could see exactly what's happening. > > > > > I am wondering of it is possible to replace these commas in the fields > > > without replacing the CSV structure. > > > > Let's get all the facts before looking for a solution. > > > > -- > > Michael Fuhr > > http://www.fuhr.org/~mfuhr/ > > > > My CSV file doesn't have quotes. > When it bugs out, what I meant to say was that when it populates the > databse, it skips columns and puts values in the wrong place. > Not really bugging out I suppose. > Sounds like the csv is not being properly generated. Without those quotes, there's really no way to know where you're trying to separate the fields. |