【问题标题】:long text in php doesn't appear correctly with htmlphp 中的长文本在 html 中显示不正确
【发布时间】:2026-01-12 22:10:01
【问题描述】:

我想查看从数据库中选择的长文本,但它出现在单行且不完整,即没有返回该行。如果我尝试手动输入文本而不是变量,效果会很好。

<div class="container">
    <h2>Discussion</h2>
        <h4><a href="school.php">School</a></h4>
        <p><?php echo $question;?></p>
        <p><label style="color: gray"> 13/03/2016 </label></p> 
</div>

【问题讨论】:

  • 如何将$question 插入数据库?
  • 这是一个 textarea ,我通过 'Insert...' 在 varchar(..) 列中插入它

标签: html php-5.5


【解决方案1】:

在将数据插入数据库时​​使用nl2br()

$text = nl2br(htmlentities($input, ENT_QUOTES, 'UTF-8'));

这将在存储到数据库时保留空白。在insert 函数中使用它。

【讨论】: