删除 Laravel 刀片中的 html 标签
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/48904815/
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
Removing html tags in Laravel blade
提问by Sava
I have an issue with deleting HTML tags. Well I get string from database
我在删除 HTML 标签时遇到问题。好吧,我从数据库中获取字符串
$desc = "<p>Test 1</p>";
And when I filter variable with htmlspecialchars and other, I have < and something else. Is there any function which can just remove tags and set variable to
当我用 htmlspecialchars 和其他过滤变量时,我有 < 和其他东西。是否有任何函数可以删除标签并将变量设置为
$desc = "Test 1";
回答by Alexey Mezenin
You can use strip_tags
:
您可以使用strip_tags
:
strip_tags(htmlspecialchars_decode($desc))
If you want to print the string with these tags used as tags:
如果要打印带有用作标签的这些标签的字符串:
{!! $desc !!}
回答by Option
just use {!! $variable !!}
to remove the tags from being visible on the output.
只是{!! $variable !!}
用来删除标签在输出上不可见。
Updated after further clarification from the op
在 op 进一步澄清后更新
because of the output you will need to use: strip_tags(htmlspecialchars_decode($desc))
由于输出,您将需要使用: strip_tags(htmlspecialchars_decode($desc))
回答by Anil Kumar Sahu
{!!$description!!}
{!!$description!!}
This is the code to remove html code however in some situation it may not work so you can also use this
这是删除 html 代码的代码,但在某些情况下它可能不起作用,因此您也可以使用它
{!! nl2br(@$description) !!}
However you can also use
但是你也可以使用
strip_tags(htmlspecialchars_decode($description))