By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,706 Members | 2,046 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,706 IT Pros & Developers. It's quick & easy.

Comma delimited file

P: n/a
I am trying to read comma delimited rows of text. The problem is that
some fields may be encapsulated in "" - particularly the text fields but
not numeric fields.

Is there a simple efficient way to parse the fields with comma but also
strip off the "" encapsulating some of the fields with php?

The problem is the "" encapsulation is optional. Some fields will have
it, some won't.

Thanks
Jul 28 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Bertie Brink wrote:
I am trying to read comma delimited rows of text. The problem is that
some fields may be encapsulated in "" - particularly the text fields but
not numeric fields.

Is there a simple efficient way to parse the fields with comma but also
strip off the "" encapsulating some of the fields with php?

The problem is the "" encapsulation is optional. Some fields will have
it, some won't.

Thanks
Once you have parsed out a field, use:

trim($field, '"'); (that's single quote - double quote - single quote)

.... which will remove " from the beginning and end of $field, if present.

--
*****************************
Chuck Anderson Boulder, CO
http://www.CycleTourist.com
*****************************
Jul 28 '06 #2

P: n/a
Bertie Brink wrote:
I am trying to read comma delimited rows of text. The problem is that
some fields may be encapsulated in "" - particularly the text fields but
not numeric fields.

Is there a simple efficient way to parse the fields with comma but also
strip off the "" encapsulating some of the fields with php?

The problem is the "" encapsulation is optional. Some fields will have
it, some won't.

Thanks
fgetcsv() possibly?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jul 28 '06 #3

P: n/a
Chuck Anderson wrote:
Bertie Brink wrote:
>I am trying to read comma delimited rows of text. The problem is that
some fields may be encapsulated in "" - particularly the text fields
but not numeric fields.

Is there a simple efficient way to parse the fields with comma but
also strip off the "" encapsulating some of the fields with php?

The problem is the "" encapsulation is optional. Some fields will have
it, some won't.

Thanks
Once you have parsed out a field, use:

trim($field, '"'); (that's single quote - double quote - single quote)

... which will remove " from the beginning and end of $field, if present.
Quotas are used for fields which (may) contain comma, so parser needs to
mind quotas and when found opening quota, should stop only on end of
line or the closing quota.
Jul 29 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.