Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php :: new line in textarea?

Tags:

How do you create a new line in a textarea when inserting the text via php?

I thought it was \n but that gets literally printed in the textarea.

Thanks

like image 875
Hailwood Avatar asked Oct 12 '10 02:10

Hailwood


People also ask

How do you add a new line in textarea?

To add line breaks to a textarea, use the addition (+) operator and add the \r\n string at the place where you want to add a line break, e.g. 'line one' + '\r\n' + 'line two' . The combination of the \r and \n characters is used as a newline character.

Does textarea support new line?

To add a new line to the default text area in messageML, textarea, use the HTML entity 
 to insert a new line.

Does \n work in PHP?

Answer: Use the Newline Characters ' \n ' or ' \r\n ' You can use the PHP newline characters \n or \r\n to create a new line inside the source code.

How do you code a new line in PHP?

The nl2br() function inserts HTML line breaks (<br> or <br />) in front of each newline (\n) in a string.


1 Answers

Without seeing your code I cannot be sure, but my guess is you are using single quotes ('\n') instead of double quotes ("\n").

PHP will only evaluate escape sequences if the string is enclosed in double quotes. If you use '\n', PHP will just take that as a literal string. If you use "\n", PHP will parse the string for variables and escape sequences and print a new line like you are expecting.

like image 153
Alan Geleynse Avatar answered Sep 21 '22 01:09

Alan Geleynse