laravel中{{}}和{!! !!}的區別詳解
1.{{}}和{!! !!} 中{{}}支持轉義 一段html代碼只是被當成普通的字符串輸出 ,{!! !!} 不支持轉義 一段html代碼可以被正常的解析
1.2具體什么意思呢我們上代碼演示
2.路由
1 Route::get('/demo', ['uses' => $namespacePrefix . 'BusinessController@demo', 'as' => 'demo']);
3.控制器
public function demo() { $address = "<span style='color:deeppink'>我的家在哪遙遠的北方</span>"; return view('business.demo')->with(['name' => '我叫張三', 'sex' => '我的性別男', 'address' => $address, ]); }
4.視圖層代碼
1 <!doctype html> 2 <html> 3 <head> 4 <meta charset="UTF-8"> 5 <meta name="viewport" 6 content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> 7 <meta http-equiv="X-UA-Compatible" content="ie=edge"> 8 <title>向視圖傳遞值</title> 9 </head> 10 <body> 11 {!!$name.$sex. $address !!}-->不支持轉義<br> 12 {{$name.$sex. $address}}-->支持轉義(我理解未轉換原來的意義) 13 </body> 14 </html>
5.顯示結果如下
鏈接:https://mp.weixin.qq.com/s/yXJjipCN9yVg_nvHRlnpnQ