php数据传入数据库时怎样保持换行?

textarea内的内容通过insert写入数据库后,怎样把文本框中的换行也存入,并且从数据库提取输出时也保持换行?

写入时做

 replace(/\n|\r\n/g,"<br>")替换
 显示时在替换回来
 str_replace("<br>",'\r',$str)

读取来的时候放入pre标签中就行

 <pre>
<?php echo "xxxx"; ?>
</pre>

读取来的时候放入pre标签中就行


<?php echo "xxxx"; ?>