码迷,mamicode.com
首页 > 其他好文 > 详细

truncate

时间:2016-06-16 06:48:12      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:

css

.ellipsis { 
    overflow: hidden; 
    white-space: nowrap; 
    text-overflow: ellipsis; 
}

php

$truncatedTitle = strlen($title) > 20 ? substr($title,0,20)."..." : $title;

blade

class AppServiceProvider extends ServiceProvider
{
    public function boot()
    {
        Blade::directive(truncate, function($expression){

            list($string, $length) = explode(,,str_replace([(,), ], ‘‘, $expression));

            return "<?php echo e(strlen({$string}) > {$length} ? substr({$string},0,{$length}).‘...‘ : {$string}); ?>";
        });
    }
}

@truncate($card->title, 20) 

truncate

标签:

原文地址:http://www.cnblogs.com/fenle/p/5589649.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!