Comma delimited file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bertie Brink

    Comma delimited file

    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
  • Chuck Anderson

    #2
    Re: Comma delimited file

    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

    *************** **************

    Comment

    • Jerry Stuckle

      #3
      Re: Comma delimited file

      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.
      jstucklex@attgl obal.net
      =============== ===

      Comment

      • Roman Ziak

        #4
        Re: Comma delimited file

        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.

        Comment

        Working...