Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

limit text using str_limit function in Laravel 5.5

I have been trying to limit my blog content text with str_limit that works fine until I apply limit of characters on it. kindly see what is missing in the code of my blade file:

{!! str_limit($blog->content) !!} works fine with the default limit, showing limited text on the view. But when I apply any custom limit i.e. {!! str_limit($blog->content, 20) !!} it do not show any text on the view.

like image 433
Shoaib Akhtar Avatar asked Dec 24 '22 06:12

Shoaib Akhtar


2 Answers

The str_limit function has been deprecated, but you can use Str::limit($text)Laravel doc.

In the php code use:

use \Illuminate\Support\Str;

The sample usage in blade:

{{\Illuminate\Support\Str::limit($text)}}
{{\Illuminate\Support\Str::limit($text,10)}}
like image 196
A1Gard Avatar answered Dec 29 '22 11:12

A1Gard


Have sorted out this thing using {!! substr(strip_tags($blog->content), 0, 150) !!} , works fine with what I was requiring.

like image 40
Shoaib Akhtar Avatar answered Dec 29 '22 11:12

Shoaib Akhtar