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)
时间: 2024-10-20 21:21:28