如何在模板 Laravel 5.6 中截断变量?

How to truncate variable in template Laravel 5.6?

我需要你的帮助来了解如何在我的模板中截断我的变量。

这是我的代码:

<p class="card-text">{{$new['content']}}</p>

我会将此变量 $new['content'] 截断为 150 个字符,末尾为“...”。

你能帮帮我吗?

我在 Laravel 5.6

上工作

谢谢大家^^

您可以使用 laravel 帮助程序 (https://laravel.com/docs/5.6/helpers#method-str-limit) 并在其后添加 ...

str_limit($new['content'], 150)

更好的方法: 如果您的内容少于 150 个字符,它不会显示 ...

str_limit($new['content'], 150, '...');
  @if(strlen($new['content'])>150)                                     
       {{substr(strip_tags($new['content']),0,150)}}...
  @else
      {{$new['content']}}
  @endif