Helena Hannah George
Helena Hannah George

Reputation: 109

How to display only a part of a string in laravel 5.2?

I have a description field with more than 100 words,but I need to show only 10 characters on my blade. How can I do this?

Upvotes: 7

Views: 17711

Answers (4)

Pirooz Jenabi
Pirooz Jenabi

Reputation: 682

You can use Str helper for Laravel.

$converted = Str::substr('The Laravel Framework', 4, 7);

return 'Laravel'

Upvotes: 0

Lonare
Lonare

Reputation: 4663

Laravel 9.x.x

If you want to show only the first character of the string, then:

{{substr($str, 0, 1)}}

Upvotes: 0

LF-DevJourney
LF-DevJourney

Reputation: 28529

use str_limit, refer to this post

{{ str_limit($string, $limit = 10, $end = '...') }}

Upvotes: 12

Shakti Phartiyal
Shakti Phartiyal

Reputation: 6254

You can show a part (first 10 characters) of a string using

{{substr($myStr, 0, 10)}}

in laravel blade template.

Upvotes: 10

Related Questions