【问题标题】:Div text won't show up as it shoulddiv 文本不会按应有的方式显示
【发布时间】:2016-07-07 04:10:01
【问题描述】:

我的 div 有问题,当我尝试使用 <?php echo $uin->text; ?> 将文本放入 div 时,它并没有像我想要的那样显示。

所以如果它起作用了,它应该是这样的:

    SOME TEXT HERE
    
    
    
    
    SOME TEXT SOME LINES BELOW


MORE TEXT AT THE BOTOM

但对我来说它总是这样显示

SOME TEXT HERE SOME TEXT SOME LINES BELOW MORE TEXT AT THE BOTOM

这是我尝试过的代码:

<style>
.TextAndStuff {
background: url(<?php echo $uin->backgroundimg; ?>);
background-repeat: no-repeat;
width: 100%;
text-align: left;
}
  </style>
  <div class="TextAndStuff">
  <?php echo $uin->text; ?>
  </div>

所以我不知道我做错了什么,但如果$uin-&gt;text 的顶部文本和中间文本之间有 3 行,它不会显示那些行,所有内容都在同一行。

【问题讨论】:

  • nl2br()函数
  • html 将忽略多个空格(空格、制表符和回车)。它也不明白什么是正常的返回字符。 @u_mulder 告诉你使用一个内置函数,它将你的字符串$uin-&gt;text 中的返回值更改为&lt;br&gt;。这样,它们将显示在新行上。 nl2br($uin-&gt;text);

标签: php html css


【解决方案1】:

就像上面说的@u_mulder 和@ThrowBackDewd 一样,使用nl2br() 函数。

在你的情况下,它会是这样的:

  <div class="TextAndStuff">
  <?php echo nl2br($uin->text); ?>
  </div>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-29
    • 1970-01-01
    • 2021-05-22
    • 1970-01-01
    相关资源
    最近更新 更多