The Little Guy Posted June 23, 2008 Share Posted June 23, 2008 in my following code, I break a text field from my db into an array (works). DB field answers may look like this: dog cat pig if I were to take the following code and break it up, into an array like in my following code, I get a line break after $q I need to remove it, but the following code won't, so my javascript doesn't work. Any suggestions? $qs = explode("\n",$row['answers']); foreach($qs as $q){ $q = str_replace("\n",'',$q); echo '<span class="feed"><input type="radio" name="question" onclick="submitPoll(\''.$q.'\')" id="poll_'.$q.'" /> <label for="poll_'.$q.'">'.$q.'</label><br /></span>'; } Link to comment https://forums.phpfreaks.com/topic/111511-solved-remove-new-line/ Share on other sites More sharing options...
The Little Guy Posted June 23, 2008 Author Share Posted June 23, 2008 I would also like to mention, that I have used trim() in place of of str_replace(), it didn't work either like so: $q = trim($q,"\n"); Link to comment https://forums.phpfreaks.com/topic/111511-solved-remove-new-line/#findComment-572284 Share on other sites More sharing options...
DarkWater Posted June 23, 2008 Share Posted June 23, 2008 $replace = array("\r", "\n", "\r\n"); $text = str_replace($replace, '', $text); Link to comment https://forums.phpfreaks.com/topic/111511-solved-remove-new-line/#findComment-572294 Share on other sites More sharing options...
The Little Guy Posted June 23, 2008 Author Share Posted June 23, 2008 perfect! Link to comment https://forums.phpfreaks.com/topic/111511-solved-remove-new-line/#findComment-572322 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.