1

I tried this but it's not chaning new lines to < br >

<textarea name="addesc" id="addesc"><?php echo $data['addesc']; ?></textarea>

$data['addesc'] = preg_replace("/\r\n|\r/", "<br />", $_POST["addesc"]); $data['addesc'] = trim($data['addesc'])

As such there's no $_POST["addesc"] on the post.php page. There's $_POST["do"]. I tried it too. No results.

RandomSeed
  • 29,301
  • 6
  • 52
  • 87
VitalSigns
  • 87
  • 8
  • Please do not edit the solution into your question. Instead, [mark one question as accepted](http://stackoverflow.com/help/someone-answers) or if none of the existing answers solved the problem, post your own an accept it. – RandomSeed Oct 22 '15 at 11:44

1 Answers1

1

There is a php function for that called nl2br.

Btw. searching for "new line to br" would have been very easy and brings up certain related topics on SO and the php manual of nl2br:

How to replace \r & \n with <br/>?

Community
  • 1
  • 1
tworabbits
  • 1,203
  • 12
  • 17
  • Maybe I am missing something but that function is not going to help me. I need to save the new lines as < br > from a textarea to DB. Does it really boil down to just using a function? – VitalSigns Oct 22 '15 at 03:47
  • 1
    Indeed it is, yes: Check this example: http://viper-7.com/kpumMr – tworabbits Oct 22 '15 at 08:22
  • Thank you. Can I ask you what exactly is TEXTAREA_INPUT in my case? Is it the `` and if it is how do I use it with the code on that page? – VitalSigns Oct 22 '15 at 10:44
  • Got it. This did it: `$data['addesc'] = htmlentities(nl2br($data['addesc']));` – VitalSigns Oct 22 '15 at 11:07
  • 1
    Remove the ´htmlentities´ call! This just to visualize the ´
    ´s when showing them in a browser.
    – tworabbits Oct 23 '15 at 01:00