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

PHP implode?

P: n/a
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
Oct 4 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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.
js*******@attglobal.net
==================

Oct 4 '08 #2

P: n/a
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_separated = implode(",", $array);

then simply:
$comma_separated .=";"

Oct 4 '08 #3

P: n/a
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?
Oct 4 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.