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,622
  • 3
  • 14
  • 11

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
  • 3,672
  • 3
  • 25
  • 37
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
  • 9,356
  • 28
  • 58
1

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

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