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);
Did you know?Explore Trending and Topic pages for more stories like this.

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

rename the file
File.txt

Code: ***DOCUMENT***
..DN:
000044255
..CB:
..SN:
..PY:
2009
..E

Just a white page
Okay so, my website, when I click SignUp on it it takes me to /join.php but its a complete white pag

Comparing two dates
Hi Guys
I have two dates I want to compare. Below is my current implementation. The problem with

Looking for help reading a .txt or .ini file and outputting the info.
I have a file called Info.ini and It has the following info:
Code: [General]
Online=0
I wou

count only commas outside parenteses
I have a sql table containing
id - query - query name
the first page contains a drop down men

Multiple Options for a Single Page
For this example I want to use the Handlers option which is under Fed Admin and all the related codi

Help to integrate whois Domain Details to website
Hi,

can i know is their any php script r methods to add domain details to my website.

Upload Code Help
Hi everyone I need some help with a bit of code ive been working with for a while. I am completely s

Libraries in C++
Hi all,

I have two libraries. one is based targeted on linux platform and uses another li

Function to extract email attachments using PHP IMAP
function extract_attachments($connection, $message_number) {

$attachments = array();

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