2017-04-06 286 views
1

我使用SmpleMDE作为我的WYSIWYG编辑器和Parsedown库来解析降价并将其转换为HTML。SimpleMDE - Markdown嵌入Youtube视频

<?php echo $this->parsedown->text($post->content); ?>

一切工作正常,唯一的问题是,我想通过添加嵌入式露面内容中 YouTube视频。

根据这个答案Youtube video and text side by side in Markdown我可以简单地添加在YouTube 直奔我的内容,但输出显示的HTML代码逃脱

<p>&lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;<a href="https://www.youtube.com/embed/7GqClqvlObY">https://www.youtube.com/embed/7GqClqvlObY</a>&quot; frameborder=&quot;0&quot; allowfullscreen&gt;&lt;/iframe&gt;</p> 

在数据库中的内容保存这样

Lorem ipsum ..... 

&lt;iframe width="560" height="315" src="https://www.youtube.com/embed/7GqClqvlObY" frameborder="0" allowfullscreen&gt;&lt;/iframe&gt; 


Lorem ipsum ..... 

我该如何解决这个问题,以便来自YouTube的嵌入代码能够正确显示?

+0

沿链的某个地方,你有一个textfilter做一些逃避标签。 '$ post-> content'的价值是什么?如果该文本看起来没问题,则会进行转换,如果不是的话,那么它就是SimpleMDE。 – glaux

+0

对帖子做了更新,Iguess在保存为db之前有一个标签转义 – Lykos

回答

0

既然问题是,字符串在数据库中的存储逃脱,试试这个:

<?php echo $this->parsedown->text(htmlspecialchars_decode($post->content); ?> 

另外,还要看看manual,您可能需要添加一个标志取决于你的字符串是如何编码/逃脱。

+0

我试图用另一种方式,比如'htmlspecialchars_decode($ this-> parsedown-> text($ post-> content))'但是没有工作。这个工作正常!谢谢 :-) – Lykos