0
votes

I am working on a form with a text box. The text box is a certain size so the input looks like this:

Hello Person,

Lorem Ipsum is simply dummy text of
the printing and typesetting industry.
Typesetting.

Thank You.

Name

Then, on another page, I query this message. I want it to display like the following. I added

$text = str_replace("\n", "\n<br />\n", $row['message']);

which helps with the spacing, but it still does not display like the following. Any ideas?

Hello Person,

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Typesetting.

Thank You.

Name

Thanks!

2
Try replacing the newlines with [NW] and inserting your message into MySQL to see if all the places you suspect that have a new line get replaced. If they don't then it may be a different spacing like \r, etc.Prix
Use nl2br to change all kinds of new line.furas
@Prix - yes, it does add new lines where it should, but it also adds new lines where it shouldn't. For example, "Thank You" and "Name" are on the differnet liens in the output, but "Lorem Ipsum is simply dummy text of" is on one line, "the printing and typesetting industry." is on one line, and "Typesetting." is on one line, because of the text field's size.Jacob
@user2521738 text field spacing does not add newlines, if something breaks down to the next line and so on because of the size, it is still a one line text.Prix

2 Answers

2
votes

If those "newlines" are just showing up because the textbox is a certain size, that is an artifact of word-wrapping; it's not actually inserting the newline character. You can double-check this by replacing "\n" with "newline", or something similar, and checking the output.

Additionally, you can use PHP's nl2br() function on the string to convert all newlines to <br>

0
votes

Try

$text = nl2br(wordwrap($row['message'], 35, "\n"));

edit: sorry misunderstood example