php - Laravel html_entity_decode 使用 UTF-8

标签 php laravel utf-8 html-entities html-encode

我正在使用 Laravel 4,以及 PHP 和 MySQL。 一切都在 UTF-8 中

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

This is an "example" post title

现在在我的网站上,我有使用 alt 的图片title属性。 当我 echo我的博客标题,我得到类似的东西:

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

这当然很糟糕。

我尝试了以下方法:

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

但是好像没什么作用。我错过了什么?

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

最佳答案

我使用的是 5.7 laravel 版本。以下解决方案解决了我的问题:

<p>{!! $pa_full_desc !!}</p>

这里 $pa_full_desc 有虚拟的 html 内容,例如。

<p>In lobortis pharetra mattis. Morbi nec nibh iaculis, <a href="#">bibendum augue a</a>, ultrices nulla. Nunc velit ante, lacinia id tincidunt eget, faucibus nec nisl.</p>

这对我有用。感谢您提出这个问题。

关于php - Laravel html_entity_decode 使用 UTF-8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25643894/

相关文章:

php - 如何在Controller Codeigniter中调用Modal Bootstrap?

php - Docker:Nginx + PHP-FPM和多个站点

php - 如何使用 PhpUnit 使用 Laravel 测试服务?

Laravel + VueJs + Webpack + Karma = 痛苦的世界

java - 使用带有 UTF-8 编码的 JXL 读取文件

php - 将数据库编码修复为 UTF8

php - PHP max_execution_time 的确切含义

php - 使用 Laravel 的 PayPal API - 更新数据

php - Laravel:表单文件上传失败 - 检测到不正确的类型

通过 http (apache httpd) 的 Perl CGI 脚本打印(utf-8 编码 - 日文 html)被截断