簡體   English   中英

如何在數據庫中插入“ Enter”

[英]How to insert “Enter” in database

我有這種情況:用戶在文本區域中插入文本。 用戶決定何時按Enter鍵,因此文本可能如下所示:

text text text text
text text
text
text text 
text

text text text text

此文本進入數據庫表,稍后在div中回顯。 問題是當它被回顯時看起來像這樣:

text text text text text text text text text text text text text

我該怎么做才能將文本插入數據庫,以使它在回顯時也顯示“ Enters”?

使用php nl2br ()函數

<?php
  echo nl2br("YOUR TEXTAREA VALUE HERE", false);
?>

只是fyi,nl2br類似於:

$details = my string with break lines given by user.

str_replace(array("\r\n", "\r", "\n"), '<br>', $details);
Or 
str_replace(array("\r\n", "\r", "\n"), '<br/>', $details);

它將捕獲所有折線,然后添加
與nl2br函數相同。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM