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

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.

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

报告相同问题?

悬赏问题

  • ¥20 fluent无法启动
  • ¥15 孟德尔随机化r语言运行问题
  • ¥15 pyinstaller编译的时候出现No module named 'imp'
  • ¥15 nirs_kit中打码怎么看(打码文件是csv格式)
  • ¥15 怎么把多于硬盘空间放到根目录下
  • ¥15 Matlab问题解答有两个问题
  • ¥15 LCD12864中文显示
  • ¥15 在使用CH341SER.EXE时不小心把所有驱动文件删除了怎么解决
  • ¥15 gsoap生成onvif框架
  • ¥15 有关sql server business intellige安装,包括SSDT、SSMS。