Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Textarea output doesn't leave lines

Tags:

html

css

php

I have a textarea in which the user enters his data. I want to make the PHP code leave lines at places where the user has. Suppose the user enters -

My name is Harry. 
I live in LA.

The out put will be

My name is Harry.I live in LA.

Please tell me the function/command we use to solve this problem(I think its a PHP problem)

Thanks in advance.

HTML Code -

<textarea rows='1' cols='50' id='p-text' class='p-textarea' placeholder = 'Write something about yourself here..'> </textarea>

I will output this in a tag, not a textarea.

@zrvan-

Output on var_dump($_GET['t'); is

string(31) "My name is Harry. I live in LA."
like image 620
user1025469 Avatar asked Jun 03 '26 20:06

user1025469


2 Answers

nl2br() should solve that if you're echo-ing the string. See: http://php.net/manual/en/function.nl2br.php

Make sure you don't strip the newlines when you add content to the database though.

like image 90
mat Avatar answered Jun 06 '26 09:06

mat


In fact the output is something like this

My name is Harry.\nI live in LA.

just use http://php.net/manual/de/function.nl2br.php for that :)

/edit: mat was faster :) flag his answer as solution :)

like image 34
Walialu Avatar answered Jun 06 '26 11:06

Walialu