i need your help to know how to truncate my variable in my template.
this is my code :
<p class="card-text">{{$new['content']}}</p>
i would truncate this variable $new['content'] at 150 characters with '...' at end.
Can you help me please ?
I work on Laravel 5.6
Thanks all ^^
@if(strlen($new['content'])>150)
{{substr(strip_tags($new['content']),0,150)}}...
@else
{{$new['content']}}
@endif
You may use laravel helper (https://laravel.com/docs/5.6/helpers#method-str-limit) and add ...
after it.
str_limit($new['content'], 150)
Much better way: it won't display ...
if ur content is less than 150 character:
str_limit($new['content'], 150, '...');