如何处理字符粘在一起的长字符串


How to handle long string where characters stick together

字符串类型1:最古老的古典希腊语和拉丁语书写单词之间几乎没有空格,可以用boustrophedon(交替方向)书写。随着时间的推移,文本方向

字符串类型2:asdasdasdasdas达斯

仅使用字符串类型1 时的示例

当我将字符串类型2添加到表中时,字符串将从表中扩展出来

如果我使用css文本溢出来控制文本:

这是带有文本溢出的css

我的问题是如何让字符串类型1显示为第一个图像,字符串类型2显示在文本溢出css 中

提前感谢您的帮助

table class="table">
                <thead>
                    <tr>
                        <th>#</th>
                        <th>Rules</th>
                    </tr>
                </thead>
                <tbody>
                    <?php $i = 1; ?>
                    @foreach ($companyrule as $companyrules)
                    <tr class="bu">
                        <th><?php echo $i++; ?></th>
                        <th> {{ $companyrules->rules}}</div></th>
                    </tr>
                        @endforeach
                    </tbody>
                </table>

一种方法是检查字符串是否超过最大长度并且不包含空格。如果是,则回显字符串的substr()并附加一些省略号,否则回显整个字符串。类似(未经测试):

$max_length = 20; // the maximum length of a string with no spaces
@foreach ($companyrule as $companyrules)
    <tr class="bu">
        <th><?php echo $i++; ?></th>
        <?php if ( strlen($companyrules->rules) > $max_length && (strpos($companyrules->rules, ' ') === false) {
             <th> {{ substr($companyrules->rules,0,$max_length )}}...</div></th>
        <?php } else { ?>
             <th> {{ $companyrules->rules}}</div></th>
        <?php } ?>
   </tr>
@endforeach

对于没有空格的长字符串,这将产生回声:

asdasdasdasdasda。。。