duanrong3308 2017-08-01 11:04
浏览 610
已采纳

在TD中的数据之间添加换行符

Looking for a way to add a line break in between the text in TD. Which is always different. I'm guessing the detecting factor would be the space between.

<tr class="garment">

  <td>Garment:</td>

  <td>gildan white 4s  basic red 10m</td>

</tr>

This would be the result im looking for

  <td>Garment:</td>


<td>gildan<br>white<br>4s<br><br>basic<br>red<br>10m</td>


</tr>

This is the code in my PHP if that helps at all. Thanks!

    <tr class="' . ($counter++ % 2 ? "odd" : "even") . '">

  <td>Garment:</td>

  <td>' . $result['garment_type'] . '</td>

</tr>

Desired code after BR splits

<tr class="garment">

  <td>Type:</td>

  <td>gildan<br>white<br>4s<br></td>

</tr>

<tr class="garment">

  <td>Type:</td>

  <td>basic<br>red<br>10m<br></td>

</tr>

展开全部

  • 写回答

1条回答 默认 最新

  • doushi1510 2017-08-01 11:08
    关注

    Change:

    <td>' . $result['garment_type'] . '</td>
    

    to

    <td>' . str_replace(' ', '<br />', $result['garment_type'] ) . '</td>
    

    This will generate the following HTML:

    <td>gildan<br>white<br>4s<br><br>basic<br>red<br>10m</td>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?