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
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.
Try
$text = 'text line one' . PHP_EOL . 'text line two';
echo '<textarea>' . $text . '</textarea>';
Will add each text on reparate line in texarea.
PHP Side: from Textarea string to PHP string
$newList = ereg_replace( "\n",'|', $_POST['theTextareaContents']);
PHP Side: PHP string back to TextArea string:
$list = str_replace('|', ' ', $r['db_field_name']);
\n
\r
<br />
^M
What Alay Geleynse said was right, I had the same problem as you and the issue was due to the escape characters (\r, \n) was there. To 'unescaped' the variable I used $var = stripcslashes($var) and it's shown correctly
i have used \p for text files. try
$row['content']=stripslashes($row['content']);
$row['content']=str_replace('<br />',"newline",$row['content']);
$row['content']=htmlentities($row['content']);
$row['content']=str_replace('newline',"<br>",$row['content']);
Use like this for dynamically enter each line you can use
echo chr(13)
来源:https://stackoverflow.com/questions/3911261/php-new-line-in-textarea