Home >Backend Development >PHP Tutorial >How to Display Raw HTML in Laravel Blade Without Escaping?

How to Display Raw HTML in Laravel Blade Without Escaping?

Linda Hamilton
Linda HamiltonOriginal
2024-12-25 13:06:09710browse

How to Display Raw HTML in Laravel Blade Without Escaping?

Displaying HTML with Blade without Escaping

In Laravel, when using Blade to display HTML within views, it's essential to escape any HTML tags to prevent malicious code execution. By default, Blade escapes HTML automatically to ensure security.

However, in certain scenarios, you may need to display HTML without escaping. For example, you might have a string like:

$text = '<p><strong>Lorem</strong> ipsum dolor <img src=&quot;images/test.jpg&quot;></p>'

When trying to display this HTML using Blade with {{$text}}, you'll notice that the output is raw HTML text instead of rendered HTML. This is because Blade escapes the HTML tags, preventing it from being interpreted as actual HTML.

To display HTML without escaping, you need to use:

{!! $text !!}

By using {!! !!}, you're explicitly telling Blade not to escape the HTML, and it will be rendered as intended. Remember, using {!! !!} should only be done when necessary and with caution to prevent potential security vulnerabilities.

The above is the detailed content of How to Display Raw HTML in Laravel Blade Without Escaping?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn