laravel中{{}}和{!! !!}的区别

1.{{}}和{!! !!} 中{{}}支持转义     一段html代码只是被当成普通的字符串输出 ,{!! !!} 不支持转移  一段html代码可以被正常的解析

1.2具体什么意思呢我们上代码演示

2.路由

Route::get('demo','DemoController@demo');

3.控制器

<?php

namespace AppHttpControllers;

use IlluminateHttpRequest;

class DemoController extends Controller
{
    //
    public function demo(){
        $address="<span style='color:deeppink'>我的家在哪遥远的北方</span>";
        return view('demo')->with([
            'name'=>'我叫张三',
            'sex'=>'我的性别男',
            'address'=>$address,
            ]);
    }
}

4.视图层代码

<!doctype html>
<html lang="en">
<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><br><br><br>
{{$name.$sex. $address}}-->支持转义(我理解未转换原来的意义)

</body>
</html>

5.显示结果如下

原文地址:https://www.cnblogs.com/yaoliuyang/p/12330283.html