pawan94's avatar

How to remove html tags from string in accessor

Hey Guys, i wanted to change my string to show from Hello to hello in view buy escaping HTML tags by defining an accessor.

public function getDescriptionAttribute()
{
    return htmlspecialchars_decode($this->description);
}

Something like this as above code is not working?

0 likes
5 replies
pawan94's avatar

This is removing the tags but if i use Hello then hello should appear in bold but it is not happening.

D9705996's avatar

Are you using {!! ... !!} tags in your blade templates as the standard {{ ... }} tags are automatically passed through htmlspecialchars?

Snapey's avatar

it would really help if you did not keep trying to post html in the forum

use backticks around your html

jlrdw's avatar

Like @NasirNobin said just use a getter setter or a helper function to strip tags:

    public static function fixStr($rvalue)
    {
        $rvalue = empty($rvalue) && !is_numeric($rvalue) ? NULL : trim(strip_tags($rvalue));
        return $rvalue;
    }

Note I get the two confused, accessor, mutator. I just use the terms getter and setter.

But in one part you say:

How to remove html tags

Another part:

change my string to show from Hello to hello in view buy escaping HTML tags by defining an accessor.

If all you are doing is making a word lower case you can do that direct:

$whatever = strtolower($whatever);

But yes you can make an accessor if you wish to do that.

Please or to participate in this conversation.