What is the e () method in laravel views?

I rummaged through the caramel, and I looked at how the views of the blade are interpreted, and that I came across the fact that:

It:

{{ $tenant->name }} 

Translated to:

 <?php echo e($tenant->name); ?> 

I don’t understand what the e() method is for? I also could not find it on php.net, so I guess this is part of laravel 5 itself. But what does it do?

+7
php laravel laravel-5
source share
2 answers

from documents:

e ()

The e function starts htmlentities on this line:

 echo e('<html>foo</html>'); // &lt;html&gt;foo&lt;/html&gt; 

http://laravel.com/docs/5.1/helpers#method-e

+13
source share

let's say that you are going to print some data from the database on a web page or are going to insert it into the database as an input, for example,

 {{ $tenant->name }} 

and the meaning of the thought $tenant->name is something like

 <script> alert("Errors...."); </script> 

after rendering in the browser you will get an alert . This is a security issue, so we need to avoid providing this content, and we do not need this data from the database.

therefore we need to misinform this data

to make laravel provide some options

HTML::entities($tenant->name);

and e() is also a helper function of HTML::entities

and you can get the same behavior using

e($tenant->name);

if $tenant->name - <script>alert("Errors....");</script> , then after applying to e() you will get something lower,

"&lt;script&gt; alert(&quot;Errors....&quot;); &lt;/script&gt;"

it is no longer a process as a script

here is a good recipe

OR is there an easy way to do this

use triple curly braces {{{ }}} instead of double curly braces {{ }} this will also sanitize the contents.

+1
source share

All Articles