Reputation: 23
I have this kind of code in my view blade:
<p class="article">
{!! strip_tags((Str::words($article->article, 25))) !!}
</p>
I want to show only the first 25 words, but sometimes it works, sometimes not. Look at the image.
P.S. Text is a writer with TinyMCE and has a lot of HTML tags.
What can be wrong?
Upvotes: 0
Views: 1305
Reputation: 389
Use this:
{!! Str::words(strip_tags($article->article), 25) !!}
Upvotes: 0
Reputation: 3623
You supposed to strip tags, and then limit words (reverse order).
{!! Str::words(strip_tags($article->article), 25) !!}
Also if this text do not supposed to be HTML code, should use {{ }}
instead {!! !!}
to avoid XSS attacks.
{{ Str::words(strip_tags($article->article), 25) }}}
Another tip will be with Str::words
. Since words can be very short or very long, and based on your screen columns should be in similar height then limiting chars instead of words will be better idea.
{{ Str::limit(strip_tags($article->article), 250) }}}
Upvotes: 1