0

I have a database system set up to store and output pages and posts in my CMS, however I am getting this returned from the database:

<p><iframe width="854" height="480" src="https://www.youtube.com/embed/PMf6PjVXRtc" frameborder="0" allowfullscreen></iframe></p>

At this point I have removed all encoding - it's just a straight CakePHP ->Save, and this appears to be the result of CakePHP's data sanitization.

        $this->save(
            array(
                'contentBody' => $data["contentBody"]
            ),
            false
        );

On the output side, what can I do to properly display this encoded HTML? The output may include regular echo or print, as well as a TinyMCE textarea.

1 Answer 1

1

You have to use html_entity_decode() before doing output. Lets say you are having output html in a variable $str use the following like for outputting:

echo html_entity_decode(html_entity_decode($str));
Sign up to request clarification or add additional context in comments.

7 Comments

I already am in one spot at least, that produces this: <iframe width="854" height="480" src="youtube.com/embed/PMf6PjVXRtc" frameborder="0" allowfullscreen></iframe> I have a feeling I'm missing something else as well.
Okay, using echo html_entity_decode($Post['Post']['contentBody']); on a plain HTML page produces the above string instead of the expected iframe output, which should display a Youtube embedded video.
I have edited my code above. Use html_entity_decode() twice on the string because cake php is encoding twice. If you find your solution mark my answer as solved and vote it up :) Thanks
Well that's one part of the issue solved. I did not honestly expect that to work in a html/php output. Now for the second half, I have to figure out why I can't get the same display in TinyMCE.
how you are outputting to tinymce ?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.