Remove HTML tags from Strings on laravel blade

自古美人都是妖i 提交于 2019-12-04 22:19:14

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.

You can use strip_tags($yourString); to strip the html tags. In blade you could achieve this by

{{ strip_tags($yourString) }} 
//if your string is <h1> my string </h1>
//output will be my string.

hope that is helpful :)

As for me, I use this construction:

{!! str_limit(strip_tags($post->text), $limit = 50, $end = '...') !!}

I hope, my code was helpful for somebody)

Add the below code into your helpers

  if (! function_exists('words')) {
        /**
         * Limit the number of words in a string.
         *
         * @param  string  $value
         * @param  int     $words
         * @param  string  $end
         * @return string
         */
        function words($value, $words = 100, $end = '...')
        {
            return \Illuminate\Support\Str::words($value, $words, $end);
        }
    }

& use this in your blade

{{ words($sentence), $limit = 20, $end = ' ..... more') }}

upendtu

You can use

{{ strip_tags( $value->description ) }}

just by doing this {!! $value !!} will solve your problem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!