Laravel 5.3 刀片解码 HTML 特殊字符

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40607589/
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 14:44:55  来源:igfitidea点击:

Laravel 5.3 blade decoding HTML Special Characters

laravel

提问by Md. Harun Or Rashid

I save some HTML Code in my Database. When I got that data to the blade, CSS not working on.

我在我的数据库中保存了一些 HTML 代码。当我将这些数据发送到刀片时,CSS 无法正常工作。

In the Page Source Code I found that < shows as '& lt;'

在页面源代码中,我发现 < 显示为 '& lt;'

What method have I to use to convert & lt to <

我有什么方法可以将 & lt 转换为 <

Is there anybody to help me?

有人可以帮助我吗?

回答by Laemol

Change your syntax from {{ }}to {!! !!}that should do the trick

将您的语法从更改{{ }}{!! !!}应该可以解决问题

回答by Rimon Khan

Try this: html_entity_decode()

尝试这个: html_entity_decode()

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

回答by Lahar Shah

{!! html_entity_decode(nl2br(e($text))) !!}
  • The efunction runs htmlentitiesover the given string.
  • nl2brInserts HTML line breaks before all newlines in a string
  • html_entity_decodeConvert all HTML entities to their applicable characters
  • e函数htmlentities在给定的字符串上运行。
  • nl2br在字符串中的所有换行符之前插入 HTML 换行符
  • html_entity_decode将所有 HTML 实体转换为其适用的字符

nl2br(e($text))and {!! !!}was ot enough to convert &quot;to "

nl2br(e($text)){!! !!}不足以转换&quot;为“

I used html_entity_decodeand then it worked exactly how I wanted. I still think it is too much for one simple thing.

我使用过html_entity_decode,然后它完全按照我想要的方式工作。我仍然认为这对于一件简单的事情来说太过分了。

回答by Gerard Reches

In order to echoHTML content as code, not as string, you must use the unescape {!! !!}syntax in your blade file. But for the issue you are experimenting, you also need to use the html_entity_decode()PHP function.

为了将echoHTML 内容作为代码而不是字符串,您必须{!! !!}在刀片文件中使用 unescape语法。但是对于您正在试验的问题,您还需要使用html_entity_decode()PHP 函数。

{!! html_entity_decode($str) !!}