duanrong3308
duanrong3308
2017-08-01 19:04

在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 doushi1510 4年前

    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>
    
    点赞 评论 复制链接分享

相关推荐