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

Request.UrlReferrer
I need to make it so that a page can only be loaded when a button is clicked on a specific page. I d

Help on query replacing the date
Hi Pals,

i want to replace the current date in a column to some value say C or D or any n

Working with Global Variables
hi, I'm not really sure why the following code is returning a "Call to a member function getBan

TimeZoneOffset
Hello,

Please i need your help. I have a system that users can use to punch in and out. This

Help: calling function
Hi,
Is it possible to call a php function on page close?
If yes, could you explain how and whe

Required to login help
I'm trying to set up my site so users have to be logged into the forum to access the site.I've been

Retreiving objects from Sessions
Hi all,

I am getting really frustrated with storing and retreiving objects from a session. Bu

JQuery, Masterpage, and Control issue
Hey everyone, I am using JQuery in several sites so I thought it would be best to place the library

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

Redirecting Admin
In my members table, I have a field called "perm" and it's set to zero for all members. Ho

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