truncate

时间:2024-01-15 20:41:38

css

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

php

$truncatedTitle = strlen($title) >  ? substr($title,,)."..." : $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)