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

Help building / using array
First - this is a cross-posting, if this is wrong I apologise! What started out as a MySQL query que

Update not working ... please help
Hi,

I am trying to update a row using an edit form by passing id of the row .. but it is not

no idea what to do...
I'm fed up. I had issues with code that I have working on a different site that didn't work on my cu

setcookie and isset($_COOKIE(name)) seem very finnicky.
I'm currently playing around with a user system with login and registration. I'm trying to use cooki

Multiple upload and Resize
I would like some help on my script I have the for my index.php

////

<html&

PHP5 - AJAX help
I've been following the tutorial on w2schools (http://www.w3schools.com/php/php_ajax_database.asp) a

TimeZoneOffset
Hello,

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

Convert .fdf to .pdf
I currently have a web form that uploads the form data to an .fdf file and emails it.

However

Run function every 5 mins ??
I have a function PostMessage()

How can I run it every 5 mins ??

Help With editting and deleting form
So look at this image :

http://img194.imageshack.us/img194/8272/snapshot5f.png
This table

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