Question

The text that I am trying to echo from $data is way too long and it is going off the screen beyond the boundaries of the table. In addition to that all the text is getting displayed without line breaks (or blank lines) or proper spacing.

My simple PHP code:

<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>

In Summary:

  1. I need the text that I am retrieving using the $data to get formatted in such a way that the line breaks are displayed in the output upon echoing.
  2. I need that output text to be scrollable so no text will go off the screen beyond the boundaries.
Was it helpful?

Solution

You can try this

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

You can also try

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

OTHER TIPS

you need to set CSS to the TD tag where you echo that $data...

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

My mistake.. TD dont accept overflow so you may do this::

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

You could echo a <pre> tag around output where whitespace is significant. Something like:

<?php echo "<pre>".Sample1_LABEL."</pre>";?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top