Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在php laravel中将字符串转换为HTML代码?_Php_Laravel - Fatal编程技术网

如何在php laravel中将字符串转换为HTML代码?

如何在php laravel中将字符串转换为HTML代码?,php,laravel,Php,Laravel,我在数据库中有一个存储脚本标记的字段,我想将这些脚本标记实现到我的HTML文件中,但问题是数据是字符串格式的 我正在尝试这个 <div class="mb-auto">{{htmlentities($video->ifram)}}</div> 您可以通过替换 {{htmlentities($video->ifram)} 与 {!!$video->ifram!!} 但是您应该非常小心XSS攻击,因为字符串中的JavaScript将由浏览器解释。永远不要使用用户提

我在数据库中有一个存储脚本标记的字段,我想将这些脚本标记实现到我的HTML文件中,但问题是数据是字符串格式的

我正在尝试这个

<div class="mb-auto">{{htmlentities($video->ifram)}}</div>

您可以通过替换

{{htmlentities($video->ifram)}

{!!$video->ifram!!}

但是您应该非常小心XSS攻击,因为字符串中的JavaScript将由浏览器解释。永远不要使用用户提供的内容

不确定是否进行了自动转义,但删除
htmlentities()
可能是一个开始。@NigelRen通过删除htmlenties(),结果是字符串格式的。有没有更安全的方法,这样我就可以逃脱
XSS攻击
因为您允许解释任意JavaScript,所以存在XSS漏洞。如果您确实需要这样做,请确保内容只能由您自己更新
<script id="154896_p_269505" width="1280" height="720" src=""  class="dacast-video"></script>
"&lt;script id=&quot;154896_p_269505&quot; width=&quot;1280&quot; height=&quot;720&quot; src=&quot;https://player.dacast.com/js/player.js?contentId=154896_p_269505&quot; class=&quot;dacast-video&quot;&gt;&lt;/script&gt;"