Jeremy
Jeremy

Reputation: 2546

Youtube iframe decoded as htmlentities

Hi i am using tinyMCE editor and having a problem retrieving the content from database.

Whenever i type this

Lorem ipsum dolor sit amet dolor amet sit dolor ipsum.
[youtube_video_here]

it successfully saved into database. However, when i tried to display it from database instead of printing the code below

<iframe ....the rest of the code

it prints

&gt;iframe ...the rest of the code &lt;&gt;/iframe>

Oddly enough it prints other HTML tags such as

<br/> or <p>

properly.

I am using PHP in CodeIgniter to retrieve the content.

Does anyone have any idea?

Upvotes: 1

Views: 1094

Answers (1)

ivanargulo
ivanargulo

Reputation: 324

There are several ways to achieve this. Not all will work for you, so you'll have to try until you find the correct solutions. Best way is to store properly the content in your database.

Variant 1. TinyMCE config. Add this line

extended_valid_elements: "iframe[src|width|height|name|align]"

More info here: extended_valid_elements

Variant 2. Decode this params before saving to the database. With PHP you'll do this:

$content = html_entity_decode($content);

Then save to your database.

Variant 3. Quick&dirty. Maybe I should start with this :)

$content = str_replace('&lt;iframe', '<iframe', $content);
$content= str_replace('&gt;&lt;/iframe>', '></iframe>', $content);
$content= str_replace('&gt;&lt;/iframe&gt;', '></iframe>', $content);

Let me know if I can be of further help.

Upvotes: 1

Related Questions