PHP implode?

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

    PHP implode?

    I'm not quite sure which function to use when I want to add a comma to
    the end of every line and a semi colon to the last one. Because it
    generates everything on the fly I can't count the rows from a db.
    Here's what I want to do:

    red, <--Comma
    green, <--Comma
    blue, <--Comma
    orange; <--Last one so semi colon

    Any help is greatly appreciated
  • Jerry Stuckle

    #2
    Re: PHP implode?

    BryanA wrote:
    I'm not quite sure which function to use when I want to add a comma to
    the end of every line and a semi colon to the last one. Because it
    generates everything on the fly I can't count the rows from a db.
    Here's what I want to do:
    >
    red, <--Comma
    green, <--Comma
    blue, <--Comma
    orange; <--Last one so semi colon
    >
    Any help is greatly appreciated
    >
    How do you know when you reach the last one?

    --
    =============== ===
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    • William Gill

      #3
      Re: PHP implode?

      BryanA wrote:
      I'm not quite sure which function to use when I want to add a comma to
      the end of every line and a semi colon to the last one. Because it
      generates everything on the fly I can't count the rows from a db.
      Here's what I want to do:
      >
      red, <--Comma
      green, <--Comma
      blue, <--Comma
      orange; <--Last one so semi colon
      >
      Any help is greatly appreciated
      Why can't you count the rows? I need a little more info, but assuming
      you have all the lines in an array; from the example given for implode()
      in the manual:

      $array = array('lastname ', 'email', 'phone');
      $comma_separate d = implode(",", $array);

      then simply:
      $comma_separate d .=";"





      Comment

      • sheldonlg

        #4
        Re: PHP implode?

        BryanA wrote:
        I'm not quite sure which function to use when I want to add a comma to
        the end of every line and a semi colon to the last one. Because it
        generates everything on the fly I can't count the rows from a db.
        Here's what I want to do:
        >
        red, <--Comma
        green, <--Comma
        blue, <--Comma
        orange; <--Last one so semi colon
        >
        Any help is greatly appreciated
        How about adding a comma at the end of every row and then after it is
        all done do a string replace for the last character?

        Comment

        Working...