brendan brendan - 3 months ago 9x
CSS Question

How to handle long string where characters stick together

String type 1:he oldest classical Greek and Latin writing had little or no space between words, and could be written in boustrophedon (alternating directions). Over time, text direction

String type 2: asdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasd

Example when only with string type 1

When I add string type 2 into the table the string will extend out from the the table

If I use css text-overflow to control the text:

Here is with text-overflow css

My question is how can I have the string type 1 showing as the first image and string type 2 showing in text-overflow css

Thanks your help in advance!!

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


One way to do it is check if the string is longer than a maximum length and contains no spaces. If so, echo out the substr() of the string and append some ellipses, otherwise echo out the entire string. Something like (untested):

$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 } ?>


For the long string with no spaces, this would echo out: