php - 使用 Blade 转义字符串,渲染 HTML

标签 php laravel laravel-5 laravel-blade

我有一个 $text 变量,其中包含一些文本和 HTML 代码。我想呈现它的 HTML,但仍要确保对字符串的其余部分进行转义。

$text = 'Example text with image <img src"image_1.jpg">. More text...'

// This will render the HTML but will NOT escape the string
{!! $text !!}

// This will escape and display the variable as raw string, with no HTML rendering
{{ $text }}

在 Laravel 5 中,有没有办法在允许 HTML 的情况下使用 Blade 转义字符串?

最佳答案

我不知道 Blade 中有这样的功能。您不能只允许特定的 HTML 标记,因为它们内部可能包含不需要的内容(如 onload)。字符串的处理可能很棘手。您是否考虑过标记语言

关于php - 使用 Blade 转义字符串,渲染 HTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29745581/

相关文章:

php - Laravel 使 :seeder is very slow

php - Laravel hasMany 和 belongsTo 参数

php - 无法使用在 AWS EC2 实例上运行的 laravel 5.2 从数据库中提取数据

javascript - 将数据传递到 vuejs 模板

php - MYSQL、PHP while循环内的两个连接

php - 如何防止 PHP 中的 SQL 注入(inject)?

php - Symfony2 依赖注入(inject)相关错误

php - 从 PHP 到 NodeJs 服务器的 HTTP Post 请求

php - Eloquent 模型中 id 周围的引号在生产站点上是必需的,但在本地主机上不起作用

php - 如何使用 laravel 中的数据库表中的数据编辑表单