如何使用PHP使我的输出文本可滚动?

时间:2012-10-21 06:03:16

标签: php html css text scrollable

我试图从$data回复的文字太长了,它超出了桌子的界限。除此之外,所有文本都显示没有换行符(或空行)或适当的间距。

我简单的PHP代码:

<div id="sampleid1" class="tabcontent" style="margin-left:48px;">
    <table width="510" border="0" cellspacing="4" cellpadding="4" class="SampleClass">
        <tr>
            <td>
                <?php echo Sample1_LABEL;?>
            </td>
            <th align="left"><strong>:</strong>
            </th>
            <td>
                <?php echo $data[ 'Sample1'];?>
            </td>
        </tr>
        <tr>
            <td>
                <?php echo Sample2_LABEL;?>
            </td>
            <th align="left"><strong>:</strong>
            </th>
            <td>
                <?php echo $data[ 'Sample2'];?>
            </td>
        </tr>
    </table>
</div>

摘要:

  1. 我需要使用$data检索的文本格式化,以便在回显时在输出中显示换行符。
  2. 我需要输出文本可滚动,因此没有文字会超出界限。

3 个答案:

答案 0 :(得分:4)

你需要将CSS设置为TD标签,在那里你回显$ data ...

<td style="height:150px; overflow-y:scroll;">

我的错误.. TD不接受溢出所以你可以这样做::

<td style="height:150px"><div style="height:100%; overflow-y:scroll;">..PHPCODE...</div></td>

答案 1 :(得分:3)

您可以在输出处回显<pre>标记,其中空格很重要。类似的东西:

<?php echo "<pre>".Sample1_LABEL."</pre>";?>

答案 2 :(得分:2)

你可以试试这个

<td>
   <div style="height:100px; overflow:auto">
      <?php echo $data['Sample2'];?>
   </div>
</td>

您也可以尝试

echo(nl2br($data['Sample2']));  //converts newline to <br /> html tag