在html文本区域添加换行符

I a trying to add a line break to a text area at run time ( ) but instead of displaying as a line break the text area physically puts in . I have read various topics about this Link 1 and link 2 without any success. It could be down to the way the data is updated within the text area but that shouldn't matter. My data is brought in through json from a php file and displayed through jQuery

Example of json response:

{"error":"2","err_msg":"","data":"<p class=\"left\">Aligned left text<\/p><br>Sub text <br>"}

The text in the text area should then display:

[left]Aligned left text[/left]
Sub text

But on my page I get

[left]Aligned left text[/left]
Sub text

I have php function to convert relevent html tags to what I want them but for some reason line breaks don't work

$string = preg_replace_callback('(\<p class="left"\>(.*?)\</p\>)is', function($matches){
   $txt = $matches[1];
   return '[left]'.$txt.'[/left]
';
}, $string);

$string = str_replace('<br>','
',$string);

die(json_encode(array('error' => '2', 'err_msg' => '', 'data' => $string)));

There is a lot more formatting and different tags but its only the line break that doesn't work.

This change should be display in a text area

$('#edit').val(json.data)
<textarea id="edit" ></textarea>

Try using the HTML entities for line feed &#10; and carriage return &#13;.

Don't use string literals encapsulated with apostrophes, try:

$string = str_replace("<br>", " ", $string)

There is a significant difference between 'this string' and "this string" in PHP; using apostrophes to encapsulate your string in PHP will treat literally as rather than chr(10).