str_limit truncates at the wrong point

Posted 1 month ago by Zaverius

Hello! First of all, I'm still learning Laravel so my apologies if my question may seem obvious.

I'm making a content manager for a project we're working on school, and I'm trying to limit the content of the news in the view. This content is saved as an HTML in the database. If str_limit truncates exactly on an image, it won't display the three dots and the rest of the website (particularly the footer) becomes visually buggy.

{!! str_limit($news->content, 550) !!}

What am I doing wrong? How can I truncate counting the HTML tags too?

Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up

Channels

Reply to

Use Markdown with GitHub-flavored code blocks.