kalster Posted October 16, 2014 Share Posted October 16, 2014 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)...helloworldI 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... Quote Link to comment https://forums.phpfreaks.com/topic/291646-array-to-string-but-hard-return-between-words/ Share on other sites More sharing options...
QuickOldCar Posted October 16, 2014 Share Posted October 16, 2014 (edited) 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 October 16, 2014 by QuickOldCar Quote Link to comment https://forums.phpfreaks.com/topic/291646-array-to-string-but-hard-return-between-words/#findComment-1493658 Share on other sites More sharing options...
QuickOldCar Posted October 16, 2014 Share Posted October 16, 2014 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; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/291646-array-to-string-but-hard-return-between-words/#findComment-1493660 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.