How can I display a string output from mySQL with CakePHP?

177

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));
Share:
177

Related videos on Youtube

Merlin
Author by

Merlin

Updated on November 29, 2022

Comments

  • Merlin
    Merlin over 1 year

    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.

    • Thomas Ward
      Thomas Ward over 10 years
      Which version of Ubuntu are you using?
    • somtam
      somtam over 10 years
      Hello... my nightmare is still unresolved. Dell support is terrible also... better don't talk about that... I reinstall everything and was ok, but after the update the problem still come out... this time I wrote down exactly the Crash Report Window: Package:oem-wireless-ath9k-3.9-rc4-2-dkms
    • Braiam
      Braiam about 10 years
      I would recommend you to report a bug, since this is not a desirable behavior of the card.
  • Merlin
    Merlin over 8 years
    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.
  • Merlin
    Merlin over 8 years
    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.
  • Furqan Aziz
    Furqan Aziz over 8 years
    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
  • Merlin
    Merlin over 8 years
    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.
  • Furqan Aziz
    Furqan Aziz over 8 years
    how you are outputting to tinymce ?
  • Merlin
    Merlin over 8 years
    Figured it out! I was accidentally using 'input' instead of 'textarea'/, and outputting the value into an input "value=" string instead of the blank space between textarea brackets. Had a moment of thought on that and decided to try replacing the form type, and it works!
  • Merlin
    Merlin over 8 years
    No wonder I wasn't getting the correct output right. Anything I did was actually triple-or quad-encoding the HTML for pages and posts. As far as I can tell, the documentation does not directly mention that CakePHP double-encodes