如何在使用 htmlpurifier 的情况下嵌入 youtu 视频?
- 修改配置文件
config/purifier.php
- 'HTML.Allowed' 增加
iframe[width|height|src|frameborder]
- 'HTML.SafeIframe' => true,
- 'URI.SafeIframeRegexp' => '%^https://www.youtube.com/embed/%',
- 'HTML.Allowed' 增加
- 禁用掉
simditor
,因为它似乎默认不支持视频。要支持可以参考。 - 接下来就可以在textarea中输入如下代码引入视频了。。
<iframe width="560" height="315" src="https://www.youtube.com/embed/WGuFofNF1Pk" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
FYA
要特别注意
config/purifier.php
中的那几个长长的属性设置,不能回车换行,否则htmlpurifier会将其当做一个空格,这样会出现类似Style attribute '' is not supported
的异常,也算是个小坑吧。。
推荐文章: