{!! str::limit($post->description, 15) !! }

  Mon 19 / 06 / 2023

  Posted by: OG Designs

Category : Laravel

Tags : laravel , php laravel

Post Thumbnail
Description

I want to remove special characters from string on my data-table under "description",

so once i add {!!   !!} my table will changed

``` {!! Str::limit($post->description, 15) !! } ```


View Code
                        <tbody>
                                @foreach($posts as $post)
                                <tr>
                                    <td class="py-1">
                                        <img src=" {{ $post->gallery->image }}" style="width: 40px" alt="image" />
                                    </td>
                                    <td> {{ $post->title}} </td>
                                    <td> {!! Str::limit($post->description, 15) !!}</td>
                                    <td> {{ $post->category->name}} </td>
                                    <td> {{ $post->is_publish == 1 ? 'Published' : 'Draft'}} </td>
                                    <td>
                                        <a href=" {{ route('posts.show', $post->id) }} " class="btn btn-sm btn-success"><i class="fas fa-eye"></i></a>
                                        <a href=" " class="btn btn-sm btn-info"><i class="fas fa-edit"></i></a>
                                        <a href=" " class="btn btn-sm btn-danger"><i class="fas fa-trash"></i></a>
                                    </td>
                                </tr>

                                @endforeach
                            </tbody>
                
  Answered by CDL

You can skip the styling using strip_tags helper and you don't need to escape the html.

Solutions

~~~

{{ strip_tags(Str::limit($post->description, 15))  }} 

~~~

Then it will print the description without html.

Solved
  Comment   Share
0 Likes   2 Comments


comment-author
OG Designs Author

Thank you Admin for your respond. Its works like this: {!! Str::limit(strip_tags($post->description), 15) !!} But in my database (myphpadmin) is still show html tags <span style="font-family: ubuntu-light, sans-serif...



Reply


commented 1 year ago
comment-author
Hadayat Niazi Super Admin

yes these styling will help you to display your description in html form, if user created any heading in description so it will display the proper heading, other text will not be readable.



comment-author
Sonam Ojha

you can use the preg_replace if you want to remove special characters from string example is this {!! Str::limit(preg_replace('/[^A-Za-z0-9\s\-]/', '', $post->description), 15) !!}



Reply


commented 1 year ago
comment-author
OG Designs Author

Sonma Thank you, its works. I appreciation for your concern. But in my database (myphpadmin) is still show html tags <span style="font-family: ubuntu-light, sans-serif...



comment-author
Hadayat Niazi Super Admin

@Sonam thank you very much for your contribution. I updated the post so you can also view the answer.