html - 如何在刀片中显示带有数据库变量的 html
问题描述
我在数据库中有带有变量的 HTML 代码我想在刀片中显示带有 html 设计和变量数据的代码
数据库代码
<ul class="dropdown-menu dropdown-menu-right">
<li>
@foreach ($block->options as $option)
<a>{{$option->name}}</a>
@endforeach
</li>
</ul>
刀片视图
@foreach ($blocks as $block)
{!! $block !!}
@endforeach
我已经显示了 html 代码,但变量仍然是字符串
解决方案
htmlentities()
在将数据保存到数据库之前,请在 html 代码字符串上使用 php 内置函数,如下所示:
$html_code = '<p class="any-class">Lorem Ipsum / Random Text</p>';
$encode = htmlentities($html_code);
/* Insert the $encode in the database cell where you want to store html */
然后当使用刀片显示带有 html 标记的单元格数据时,您执行此操作{{!! html_entity_decode($block) !!}}
这会很好用!!!干杯!!
推荐阅读
- python - windows cmd中两个python程序的diff输出
- python - 如何查找并突出显示两个文本文件之间的差异?
- vba - Excel VBA在不同的工作表中堆叠列
- angular - 更新firestore数据后显示重复事件,但firestore中的数据本身不重复
- wordpress - WordPress 将每个页面和文件作为主页
- firebase - Firebase 云消息传递示例不起作用
- vba - 自动筛选不显示现有数据
- apache-camel - Camel bean 组件调用 @Named / @Dependent bean 的缓存实例
- json - Angular 5 无法从 json 正确解析时间戳
- google-cloud-platform - 限制对 GCP Console for Enterprise 的登录访问