Home > Backend Development > PHP Tutorial > What is the difference between {{}} and {!! !!} in Laravel?

What is the difference between {{}} and {!! !!} in Laravel?

黄舟
Release: 2023-03-16 11:28:01
Original
5648 people have browsed it

The difference between "{{}}" and "{!! !!}" in Laravel: "{{}}" supports escaping, and a piece of html code is just output as an ordinary string; "{ !! !!}" does not support escaping, and a piece of html code can be parsed normally.

What is the difference between {{}} and {!! !!} in Laravel?

##The difference between {{}} and {!! !!} in Laravel

{{}} Supports escaping, a piece of html code is just output as an ordinary string; {!! !!} does not support escaping, and a piece of html code can be parsed normally.

What does it mean specifically? Let’s show the code:

Routing

Route::get('/demo', ['uses' => $namespacePrefix . 'BusinessController@demo', 'as' => 'demo']);
Copy after login

Controller

public function demo()
{
    $address = "<span style=&#39;color:deeppink&#39;>我的家在哪遥远的北方</span>";
    return view(&#39;business.demo&#39;)->with([&#39;name&#39; => &#39;我叫张三&#39;,
        &#39;sex&#39; => &#39;我的性别男&#39;,
        &#39;address&#39; => $address,
    ]);
}
Copy after login

View layer code

<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>向视图传递值</title>
</head>
<body>
{!!$name.$sex. $address !!}-->不支持转义<br>
{{$name.$sex. $address}}-->支持转义(我理解未转换原来的意义)
</body>
</html>
Copy after login

Display results As follows

For more related knowledge, please visit What is the difference between {{}} and {!! !!} in Laravel?PHP Chinese website! !

The above is the detailed content of What is the difference between {{}} and {!! !!} in Laravel?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
Statement of this Website
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
Latest Issues
Composer cannot install laravel
From 1970-01-01 08:00:00
0
0
0
Laravel Space/laravel-backup cannot be installed
From 1970-01-01 08:00:00
0
0
0
Laravel 5.1 Login laravel comes with it No more
From 1970-01-01 08:00:00
0
0
0
Why thinkphp has better performance than laravel?
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template