Reputation: 6799
I have a textarea as an input in my HTML form. When any user writes something like following (I am trying to point out the line breaks):
The quick brown fox jumps **over**
the lazy dog
And when it is stored into database and I retrieved it and echo it appears without the line breaks, it looks like following:
The quick brown fox jumps over the lazy dog
Could you please tell me how to display the stored data in just the way it was formatted by the user?
When I display data I just retrieve information from database just the usual way and then just echo it like this-- <? echo $value_text ;?>
Thanks in Advance :0
Upvotes: 0
Views: 65
Reputation: 15676
You just need to wrap the text in an nl2br()
function like this: <? echo nl2br($value_text);?>
. This will convert all new lines into <br>
tags.
When your page loads, the php echo gets interpreted as html. As you know, new lines in HTML don't affect the layout of a page. This is why you need every line break converted into a <br>
tag.
Upvotes: 1
Reputation: 4778
Are you sure the line breaks don't exist?
If you are using this on a website, you may need to replace the line break with a
tag.
echo nl2br($data);
Or you can alternatively wrap the text in <pre>
tag's
Upvotes: 1