1

I'm having an issue whenever I enter text into a text area and submit it to my database. The text automatically gets a <br /> tag tacked onto the end of the input. I'm not sure why and whenever I try to do the str_replace, it only works the first time.

Keep in mind that I have text pre-placed in the text area from a query in order to be able to edit it.

$query->text = str_replace("&lt;br /&gt;", "", $query->text);
<textarea id= "custom" name="text" rows = "10" column = "50">
    <?php echo $query->text; ?>         
</textarea>   
Passerby
  • 9,715
  • 2
  • 33
  • 50
  • http://php.net/manual/en/function.nl2br.php Duplicate of http://stackoverflow.com/questions/5946114/replace-r-n-with-br – krowe Apr 11 '14 at 00:21
  • Also, this should only be done when displaying the text. Just store new lines in the DB. The DB shouldn't concern itself with how the text will be used by the client. – krowe Apr 11 '14 at 00:24
  • Errrrr, I didn't mean to put \r\n, I meant to just replace it with "". I don't want any breaks or new lines at all. –  Apr 11 '14 at 00:25
  • What do you mean by "it only works the first time?" – merlin2011 Apr 11 '14 at 00:26
  • Then you want: http://stackoverflow.com/questions/3760816/remove-new-lines-from-string – krowe Apr 11 '14 at 00:26
  • @merlin2011 It only replaces text on the first table entry I edit. Every other one after that still has the trailing br tag. –  Apr 11 '14 at 00:30
  • @Requiem, Then I would assume you are running this in some kind of loop. Please show that loop in your question. – merlin2011 Apr 11 '14 at 00:33
  • There is no loop. This is just set up in MVC and just consistently calls upon a row and queries for the data when a button is pressed. –  Apr 11 '14 at 00:35
  • Did you try logging the value of `$query->text` before calling the function, so you can at least verify the exact string before you try the replace? – merlin2011 Apr 11 '14 at 00:36
  • I've checked the string multiple times. Can anyone explain to me first why the "<br />" tag shows up in the first place? –  Apr 11 '14 at 00:48
  • try to coding in single line without any line-break, ` ` – Allen Chak Apr 11 '14 at 06:38

0 Answers0