0

I have this code:

href="#0">{{$article->title,}}

How do I limit the title to certain characters with "..." at the end?

Thank you!

Sam Mitchell
  • 3,442
  • 3
  • 13
  • 10

3 Answers3

3

You can use 2 methods to do this:

Method 1:

 //I am assuming that you need to print first 20 characters from the title
 {{ substr($article->title, 0,  20) }}

Method 2:

 {{ Illuminate\Support\Str::limit($article->title, 20) }}
Ankit Jindal
  • 2,805
  • 3
  • 19
  • 30
2

Laravel provides a function for this specific usage:

{{ Str::limit($article->title, 100, '...') }}

100 is the number of characters to keep,

... is the string to append after truncating

gbalduzzi
  • 8,482
  • 27
  • 54
1

You can use substr(); https://www.w3schools.com/php/func_string_substr.asp

{{substr("Hello world",0,25)}}...