2016-07-22 88 views
0

字符串類型1:他最古老的古典希臘文和拉丁文寫作在單詞之間很少或沒有空格,並且可以寫成boustrophedon(交替方向)。隨着時間的推移,文字方向如何處理字符粘在一起的長字符串

字符串類型2: asdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasdasd

Example when only with string type 1

當我添加字符串類型2到表中的字符串將從表伸出

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

Here is with text-overflow css

我的問題是我怎麼能有string類型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> 
+0

添加你的CSS文件 – Zoe

+0

您可以使用此'table td,table th word-wrap:break-word; }' – Phil

回答

1

一種方式來做到這一點是檢查字符串的長度超過最大長度,並且不包含空格。如果是這樣,請回顯字符串的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 

對於長字符串沒有空格,這將回聲出:

asdasdasdasdasdasda ...

+1

明白了!感謝您的解決方案。 – brendan

+0

很高興。讓我知道你是否不正確 –