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

Replacing a string on click of a button
Hi! Is there a way to replace a string on a click of a text link?

This is what I've come up w

Question about ShowWindow()
Hello....

I'm struggling with sumpin, and I hope y'all can help.

I've got a CFormView

Easy administration on MySQL databases
My website is database driven and I am very tired of manually making queries to my tables in order t

Is it possible to stop reservation creation in PM Order?
Hi All,

Is it possible to stop reservation creation in PM Order?

Thanks in adv

Calander Basic Spript help
hi, just starting out with PHP and have the following script:

<?php
//This gets t

Adding post count
How would I make it so everytime someone clicks submit on my form, their row in the database for the

for loop without same $i digits?
Hi,

Can some guru please advise how can I accomplish this with a simple for loop ?

I

Return X values where an ID number doesnt matter
Well as for subject heading, thats the best i could think of.

Currently im having a problem w

I need help on this PHP code
Hi everybody, I made some kind of mistake while editing the code below. As you see, at the 3 row my

Insert Failing.
Hey,
I am making a Sign up page for a website, but the insert query into the Database does not se

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