chochobot
chochobot

Reputation:

How to accept "enter" value?

I am using php5. I am doing a form, a textarea, where user can send it to his/her friends. But currently, in my textarea form, if i type :

Hello XXX,

Its been a while. How are you?

But when I echo it, it displays

Hello XXX, Its been a while. How are you?

How do I accept the enter button, so that when I display I can display like:

Hello XXX,

Its been a while. How are you?

Upvotes: 1

Views: 598

Answers (1)

Ólafur Waage
Ólafur Waage

Reputation: 70001

There is a function called nl2br() which converts newlines \n to html friendly line breaks. <br> or <br />

It's used like this

echo nl2br("foo isn't\n bar");

This will output

foo isn't<br />bar

Since HTML is markup based, you will need some markup to tell the browser that you want a linebreak.

The reason is that

<p><b>Hello <i>World</i></b></p>

Is the exact same thing as

<p>
<b>
Hello 
<i>
World
</i>
</b>
</p>

Upvotes: 7

Related Questions