Comma seperated implode & modifying returned string.


Posted on 16th Feb 2014 07:03 pm by admin

I have a PHP post form that posts up to 4 variables. I need whatever variables are passed to be combined into one comma seperated string (eg variable1,variable2,variable3,variable4). This i can do with the code below.

Code: [Select]$combo = array($one, $two, $three, $four);
$list = implode(",", $combo);

my problem is that the form fields are optional by design so that the user doesn't always post all 4 variables. Sometimes they will post 1, sometimes they will post all 4. So if a user only selects two fields and submits the form i will end up with a string looking like:
variable1,variable2,,
when what i really want is (note the removal of the trailing commas at the end of the string):
variable1,variable2

Can anyone point me towards a possible solution for this?

No comments posted yet

Your Answer:

Login to answer
297 Like 14 Dislike
Previous forums Next forums
Other forums

Quick variable question
hey guys/gals,
im trying to write a php script and it works fine as i have it, but i need to set

Spliting paragraph into sentences and attach in
Here is what I am trying to do

example: Para1[123.456.789!] 3 sentences
Para2

Help with setcookie()
Merry Xmas to those on this foruum
Older guy here with some experience but not allot so please be

Entering Data Problem
Code: $result = mysql_query("SELECT * FROM flights");
while ($row = mysql_fetch_array($

calculator
I can't figure out why this code doesn't work. No error messages. Page loads.

Code: <

Add code to enable passing of checkbox variable on login
Ok, I have a login page, but want to add a checkbox that when checked and successful login is made i

How do I give a developer access to a specific directory and nothing else?
I want to give a develop access to a specific directory and nothing else

I can give them an F

Multi Dimensional Array Append
Hi Guys

I have a function that returns a multidimentional array eg

$result = functio

Undefined offset when using a flat file with pipe symbols
Hi, I've got a flat file/text file which I'm currently using as a member database for my site (not a

Prevent PHP mail( ) from appending hostname to from address
Hey guys,

I want to be able to send texts to phones via email (since each phone has their own

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash