Search code examples
laravellaravel-4laravel-5

Remove HTML tags from Strings on laravel blade


I want to remove HTML tags (all) from a string on laravel blade ...

code

{!! \Illuminate\Support\Str::words($subject->body, 5,'...')  !!}

output (example)

<p>hassen zouari</p>

I want it be like this

hassen zouari

Solution

  • Try to use strip_tags() function:

    http://php.net/manual/en/function.strip-tags.php

    Update: Try to do something like this in a controller:

    $taglessBody = strip_tags($subject->body);
    

    Then pass this variable into a blade template and use it instead of $subject->body.