0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Laravelの{{ }}はhtmlspecialcharsではなくhtmlentitiesだった

Posted at

LaravelのBladeの{{ }}

HTMLのサニタイズはhtmlspecialcharsです。
LaravelのBladeの{{ }}ってhtmlentities です。

##htmlspecialcharsとhtmlentitiesはどう違うの?

htmlspecialcharsがHTMLにおける特殊文字をHTMLエンティティに変換するのに対して、
htmlentitiesは適用可能な文字を全て HTML エンティティに変換します。

なので、¥とか©とか×とか÷とか、
普段よく使う記号も変換するので、意図せず使っている方は注意!

print htmlspecialchars('¥');
// ¥
print htmlentities('¥');
// ¥

print htmlspecialchars('©');
// ©
print htmlentities('©');
// ©

print htmlspecialchars('×');
// ×
print htmlentities('×');
// ×

print htmlspecialchars('÷');
// ÷
print htmlentities('÷');
// ÷

ちなみにe()もhtmlentities。

ヘルパー関数のe()もhtmlentitiesです。

##参考リンク
https://aoma23.hatenablog.jp/entry/2016/12/14/Laravel%E3%81%AE%7B%7B_%7D%7D%E3%81%AFhtmlspecialchars%E3%81%A7%E3%81%AF%E3%81%AA%E3%81%8Fhtmlentities%E3%81%A0%E3%81%A3%E3%81%9F

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?