Because the line-wrapping in the textarea is "\ n" or "\ r \ n" (Linux is entered as ' \ r \ n ', Windows is ' \ n ') the newline in normal HTML is <br/> or <br>;
Situation one, if the content of the textarea directly into the database, the newline in the database will also be "\ n" or "\ r \ n" Storage
Workaround for this situation:
Method one, (use Smarty template)
1. In the PHP server
$str = Str_replace ("\ r \ n", "<br/>", $value);(or $str = Str_replace ("\ r \ n", "<br>", $value);)
$this->data[' value ']= $str;
2. At the template end
{$value |replace: "<": "<" |replace: ">": ">"}
Method II, (using the Smarty template, this approach is not correct in some frameworks, because these frameworks will be in the server to pass <br>, after the browser parsing will be ' < ' and ' > ' Resolution to ' < ' and ' > ')
1. In the PHP server
$str = Str_replace ("\ r \ n", "<br/>", $value);
$str = Htmlspecialchars_decode ($STR);
$this->data[' value ']= $str;
2. At the template end
{$value}
Method III (no use of smarty template)
1. In the PHP server
$str = Str_replace ("\ r \ n", "<br/>", $value);(or $str = Str_replace ("\ r \ n", "<br>", $value);)
$this->data[' value ']= $str;
2. At the HTML end
<?php Echo Html_entity_decode ($value, ent_quotes);? >//Conversion of special HTML entities (including < and > etc.) back to normal characters (' < ' or ' > ', etc.)
Second, the content of the textarea will be processed before warehousing, and then take the value from the library to do once again processing.
Summary: Situation one and situation two are only two different steps, thinking the same
The following are reproduced others, can be used as a reference,
The workaround is as follows:
I. Form processing
Use JavaScript at commit to replace \ n in textarea with <br>, where jquery is used.
<textarea name= "Test" rows= "3" cols= "a" id= "test" ></textarea>
<script type= "Text/javascript" >
$ ("#form"). Submit (function () {
var Descrip = $ ("#test"). Val ();
Descrip=descrip.replace (/\n/g, ' <br/> ');
$ ("#test"). Val (Descrip);
}
</script>
Two. Service-side processing
Using PHP's built-in function, do a bit of storage before the processing
Htmlentities (Trim ($postValue), ent_quotes, "utf-8");
Three. Read the Display page
Use PHP's regular function to put the read <br> restore, and then output
<?php
$show = eregi_replace (' <br>|<br/> ', ' <br> ', $dataStr);
?>