Laravel html_entity_decode 使用 UTF-8

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25643894/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 10:02:01  来源:igfitidea点击:

Laravel html_entity_decode using UTF-8

phplaravelutf-8html-entitieshtml-encode

提问by PhilMarc

I am using Laravel 4, with PHP and MySQL. Everything is in UTF-8

我正在使用带有 PHP 和 MySQL 的 Laravel 4。一切都在 UTF-8

I have blog titles stored in my database, that look like :

我的数据库中存储了博客标题,如下所示:

This is an "example" post title

This is an "example" post title

Now on my website, I have images using alttitleattributes. When I echomy blog title, I get something like:

现在在我的网站上,我有使用alttitle属性的图像。当echo我的博客标题时,我会得到类似的信息:

<img src="image.jpg" alt="This is an "example" post title" />

<img src="image.jpg" alt="This is an "example" post title" />

Which of course is terrible.

这当然是可怕的。

I have tried the following:

我尝试了以下方法:

{{ html_entity_decode($blog_title, ENT_QUOTES, 'UTF-8') }}

{{ html_entity_decode($blog_title, ENT_QUOTES, 'UTF-8') }}

But it doesn't seem to do anything. What am I missing?

但它似乎没有任何作用。我错过了什么?

I would like the title to display like this: This is an &quot;example&quot; post title

我希望标题显示如下: This is an &quot;example&quot; post title

回答by Boldewyn

Use triple curly quotes:

使用三重引号

{{{ $blog_title }}}

The html_entity_decode()does the opposite (and hence leaves "untouched). As a memory hook:

html_entity_decode()做相反的事情(因此保持"不变)。作为内存挂钩:

" -> encoding -> &quot;
&quot; -> decoding -> "