1

我使用SmpleMDE作为我的 WYSIWYG 编辑器和Parsedown库来解析 markdown 并将其转换为 HTML。

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

一切正常,唯一的问题是我想通过添加嵌入的<iframe>.

根据这个答案Youtube 视频和文本在 Markdown 中并排,我可以简单地将 youtube<iframe>直接添加到我的内容中,但是输出显示 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 的嵌入代码能够正确显示?

4

1 回答 1

0

由于问题是字符串被转义存储在数据库中,试试这个:

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

另外,请查看手册,您可能必须根据字符串的编码/转义方式添加一个标志。

于 2017-04-06T13:00:21.417 回答