我有一个 $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/