Jump to content

array to string but hard return between words


kalster

Recommended Posts

 hello, i seem to be stuck again and this bug is difficult for me to solve.

if(isset($_POST['boards']))
	$boards[] = $_POST['boards'];
$allboards = implode("",$boards[0]);
echo $allboards;

outputs (browser source)...
hello
world

I have a combobox with the "multiple" property.  when two items are selected, the combobox "name" property has an array that passes to the $_POST variable. what i would like is those two words to be displayed on the same line.
I have tried rtrim($var, "\r\n") but that does nothing.

the reason i need them on the same line is because i would change then to "hello, world" and then add them as a mysql query, for example... $query = "SELECT hello, world FROM table...

Link to comment
Share on other sites

Not sure why making that an array and back, this could work.

if(isset($_POST['boards']) && trim($_POST['boards']) != ''){//check if is set and not empty
$boards = trim($_POST['boards']);//trim end whitespace
$boards = preg_replace('/\s+/', ' ',$boards);//remove multiple spaces
$boards = str_replace(" ",",",$boards);//replace space with comma
echo $boards;
}
Edited by QuickOldCar
Link to comment
Share on other sites

Unless you mean something like this with multiple checkboxes

<form method="POST" >
one: <input type="checkbox" name="boards[]" value="one"/>
two: <input type="checkbox" name="boards[]" value="two"/>
three: <input type="checkbox" name="boards[]" value="three"/>
<input type="submit" name="search" value="Search"/>
</form>
<?php
if(isset($_POST['boards']) && trim($_POST['boards']) != ''){//check if is set and not empty
$allboards = implode(",",$_POST['boards']);
echo $allboards;
}
?>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.