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));
Related videos on Youtube
Author by
Merlin
Updated on November 29, 2022Comments
-
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>&lt;iframe width="854" height="480" src="https://www.youtube.com/embed/PMf6PjVXRtc" frameborder="0" allowfullscreen&gt;&lt;/iframe&gt;</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 over 10 yearsWhich version of Ubuntu are you using?
-
somtam over 10 yearsHello... 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 about 10 yearsI would recommend you to report a bug, since this is not a desirable behavior of the card.
-
-
Merlin over 8 yearsI 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 over 8 yearsOkay, 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 over 8 yearsI 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 over 8 yearsWell 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 over 8 yearshow you are outputting to tinymce ?
-
Merlin over 8 yearsFigured 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 over 8 yearsNo 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