Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

eddy1992's avatar

How to limit string data in view

Hi I am making a cms now I have a view in which the description of the blog post needs to be small but it would print all the data coming from the database i.e blog->description will print all the data .

What I want is the description to be limited so that the user could click on Read More button to view all the content.

My view in which $blog->blogs_description is printing all the data.

0 likes
13 replies
pmall's avatar

Use google to find an excerpt function which suits you.

bashy's avatar
bashy
Best Answer
Level 65

Should be able to use

Str::limit($value, $limit = 100, $end = '...')

str_limit() // is a helper

or

Str::words($value, $words = 100, $end = '...')

depending on if you want to end on a letter or word.

5 likes
johnef_sh's avatar

@bashy yes nice but you don't have to write with $limit and $end

Str::limit($value, $limit = 100, $end = '...')

this will work too

str::limit($value, 100, '...')

short and sweet :)

bashy's avatar

@johnef_sh Yes, most programmers will know that. I copied it from the Laravel API so it shows what params you can use and their default values.

Nice try :P

4 likes
rhoyle's avatar

trying to get this " {{ str_limit( $project->description) }}" to work any help wood be appreciated getting this "Call to undefined function str_limit() (View: C:\xampp\htdocs\imr-orders\resources\views\projects\index.blade.php)" error message

tariquedev's avatar

try to use str_limit($blog->blogs_description, 50);

Please or to participate in this conversation.