What is the difference between {{ }} and {!! !!} in laravel blade files?

PhpLaravelLaravel 5.2Laravel Blade

Php Problem Overview


In the laravel framework we can use blade to add PHP code in html file.
We are using both {{ }} and {!! !!} syntax in blade files of Laravel.
What is the difference between them?

Php Solutions


Solution 1 - Php

>Blade {{ }} statements are automatically sent through PHP's htmlentities function to prevent XSS attacks.

If you pass data from your Controller to a View with some HTML styling like:

$first = "<b>Narendra Sisodia</b>";

And it is accessed, within Blade, with {{ $first }} then the output'll be:

<b>Narendra Sisodia</b>

But if it is accessed with {!! $first !!} then the output'll be:

Narendra Sisodia

Solution 2 - Php

If you don't want the data to be escaped then use {!! !!} else use {{ }}.

Solution 3 - Php

from the documentation: https://laravel.com/docs/5.1/blade

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 !!}.

Solution 4 - Php

To escape data use

{{ $data }}

If you don't want the data to be escaped use below

{!! $data !!}

Solution 5 - Php

Blade {{ }} statements are automatically sent through PHP's htmlentities function to prevent XSS attacks.

You can see more here:https://laravel.com/docs/master/blade

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionKumaranView Question on Stackoverflow
Solution 1 - PhpNarendrasingh SisodiaView Answer on Stackoverflow
Solution 2 - PhpSougata BoseView Answer on Stackoverflow
Solution 3 - PhpmehariView Answer on Stackoverflow
Solution 4 - PhpPoorna RaoView Answer on Stackoverflow
Solution 5 - PhpPanagiotis KoursarisView Answer on Stackoverflow