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
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.
To add a new line to the default text area in messageML, textarea, use the HTML entity to insert a new line.
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.
The nl2br() function inserts HTML line breaks (<br> or <br />) in front of each newline (\n) in a string.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With