Limiting number of characters displayed in table cell

后端 未结 4 378
渐次进展
渐次进展 2021-01-27 11:48

I have a PHP loop that adds data into a table cell. However, I want to apply a static size to the table cell, so if more data is returned than can fit inside the cell I want th

4条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-27 12:28

    You can use mb_strimwidth

    printf('%s', mb_strimwidth($cellContent, 0, 100, '…'));
    

    If you want to truncate with respect to word boundaries, see

    • Truncate a multibyte String to n chars

    You can also control content display with the CSS property text-overflow: ellipsis

    • http://www.quirksmode.org/css/textoverflow.html

    Unfortunately, browser support varies.

提交回复
热议问题