简体   繁体   English

nl2br和htmlentities在textarea上

[英]nl2br and htmlentities on textarea

So i have this textarea where i want people to be able to write stuff about themself and be able to use quotes around specific words and at the same time be able to make new section of text without have to write the <br> . 因此,我在这个textarea中,我希望人们能够写一些关于他们自己的东西,并能够在特定单词周围使用引号,同时又能够撰写新的文本部分而不必编写<br> I tried doing this but i failed. 我尝试这样做,但失败了。 What am i doing wrong? 我究竟做错了什么?

<textarea id="about"></textarea>

$about = nl2br($_POST["about"]);

$text = htmlentities($about, ENT_QUOTES);

$query = "INSERT INTO text VALUES('', '$text'";
$query_run = $db->query($query);

I inserted this into my database, but when i try to echo it out, the break doesn't apear. 我将此插入到数据库中,但是当我尝试将其回显时,中断不会出现。

$id = $_POST["id"];
$sql = "SELECT * FROM text WHERE id = '$id'";
$sql_run = $db->query($sql);
while($row = mysqli_fetch_assoc()){
   $about = $row["about"];
   echo $about;
}

example of what it looks like when i insert it. 我插入时的外观示例。

cola&lt;br /&gt;&lt;br /&gt;cola&lt;br /&gt;&lt;br /&gt;&quot;cola&quot;&lt;br /&gt;&lt;br /&gt;love that stuff!

$_POST["about"] will be with \\n so you don't need to use nl2br() with it. $_POST["about"]将与\\n一起使用,因此您不需要对其使用nl2br()

Use it when you're displaying the value on a page. 在页面上显示值时使用它。 (eg echo nl2br($about) ) (例如echo nl2br($about)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM