Reputation: 9
For example here is my text etc.
now here is the newline.
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?
Upvotes: 0
Views: 5816
Reputation: 2600
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";
Upvotes: 3
Reputation: 5812
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';
Upvotes: 0