How do I add or save new lines in a textarea box with php?
For example here is my text etc.
now here is the ne开发者_Python百科wline.
How do I create that new line in php I normal need to hold Ctrl and Enter to create it it this textarea box?
Does it require javascript?
if you want to set the default text of a textarea you don't need php. You just need to set its value attribute with something as "Your text.\nAnother line", where '\n' will get replaced by a new line. Alternatevely you can do it through Javascript if you set the attribute dynamically, as in:
document.getElementById("id_of_your_textarea").value = "Your text\nAnew line";
You will need to use so-called "escape sequence". You can find list of all escape sequences on PHP Manual. Escape sequences only work in strings in double quotes.
$string = "My string\nWith a line breaks\ninserted"; // notice the \n
$no_escapes = 'This will not replace \n with a line break';
精彩评论