M
M
marq2022-04-02 11:38:49
Laravel
marq, 2022-04-02 11:38:49

Laravel how to crop text?

there is a text that I enter through the summernote editor, when outputting the text, I need to cut it to 200, I tried it like this

{!!Illuminate\Support\Str::limit($post->text,200)!!}
But it doesn’t work I also tried it like this :

{{Illuminate\Support\Str::limit($post->text,200)}}
But then the styles and tags are displayed along with the text

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Helldar, 2022-04-02
@Helldar

As a rule, wysiwyg passes html markup. The Laravel helper does not know how to crop with it in mind.
Therefore, there are three options here:
1. Before cropping, execute strip_tags in order to remove all tags from the text;
2. Trim the length taking into account the tags, because they will also be included in these 200 characters, and get a curve markup;
3. On the front side, check the text length with a script before sending, and on the back side, when receiving, remove tags, get the length and compare with the allowed one.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question