1

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?

Community
  • 1
  • 1
ltdev
  • 4,037
  • 20
  • 69
  • 129
  • Somewhere along the chain you have a textfilter doing some escaping of the tags. What is the value of `$post->content`? If that text looks okay, it's parsedown that makes the conversion, if not, then it's SimpleMDE. – glaux Apr 06 '17 at 12:49
  • Did an update on post, Iguess there's an escaping on tags before saving in db – ltdev Apr 06 '17 at 12:57

1 Answers1

0

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.

glaux
  • 701
  • 7
  • 20
  • I was trying this the other way around, like this `htmlspecialchars_decode($this->parsedown->text($post->content))` but didn't work. This one works fine! Thanks :-) – ltdev Apr 06 '17 at 13:08