1

I have a PHP variable in Laravel controller: $html= '<img src="/example.png">'

Then in view blade, I displayed it with {{$html}}.

But it isn't rendered as html element. It shows as a text/string like <img src="/example.png"> in browser.

Tridev Shrestha
  • 447
  • 7
  • 21
SuperAsker
  • 41
  • 6

2 Answers2

3

You should use:

{!! $html !!}

Check this answer, it is also documented on the official documentation, on the section Displaying Unescaped Data

namelivia
  • 2,657
  • 1
  • 21
  • 24
  • 1
    Anyone reading this, just remember that *unescaped* means **dangerous** if any part of the string comes from user input. – Travis Britz Feb 28 '19 at 08:23
0

Displaying Unescaped Data

By default, Blade {{ }} statements are automatically sent through PHP's htmlentities function to prevent XSS attacks. If you do not want your data to be escaped, you may use the following syntax:

Hello, {!! $name !!}.

Ref. https://laravel.com/docs/5.1/blade#displaying-data

Vipertecpro
  • 3,056
  • 2
  • 24
  • 43