douwen0612 2017-04-06 12:18
浏览 269
已采纳

SimpleMDE - Markdown嵌入来自Youtube的视频

I 'm using SmpleMDE as my WYSIWYG editor and the Parsedown library for parsing the markdown and converting it into HTML.

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

Everything works fine, the only problem is that I want to show up youtube videos within the content by adding the embeded <iframe>.

According to this answer Youtube video and text side by side in Markdown I can simply add the youtube <iframe> straight to my content, however the output shows the html code escaped

<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>

The content in the database is stored like this

Lorem ipsum .....

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


Lorem ipsum .....

How can I fix this so that the embeded code from youtube would show up properly?

  • 写回答

1条回答 默认 最新

  • duanniying2342 2017-04-06 13:00
    关注

    Since the problem is that the strings are stored escaped in the database, try this:

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

    Also, take a look at the manual, you might have to add a flag depending on how your strings are encoded/escaped.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?