bentobenji Posted April 28, 2009 Share Posted April 28, 2009 PHP Version 5.2.5 entropy release 6 php mysql library versions 5.0.45 mysql vx 5.1.32 on server localhost via unix socket There has got to be a simple answer, so I would appreciate if someone is nice enough to help out this newbie. Basically, I have medium sized data with html tags in it. I want to read the data into a php variable with the html tags in tact to then display it correctly in the browser. I can get my data and print/echo it, but it converts the html tags into ascii characters rather than the appropriate html rendering. I'm able to grab the data on my little zend framework site using the foreach loop and a conditional and storing in it a var like '$content2'. This works beautifully so no need to give code for that. Then when I go to display one of the content variables like so: <?php print $content2; ?> It renders all of the HTML in the data as ascii. E.g., the bit of data from mysql '<h2>Hot off the press!</h2>' is rendered in the source code as '<h2>Hot off the press!</h2>', In other words, it renders literally '<h2>Hot off the press!</h2>' in the web browser. I've done this before with XML by putting <![CDATA[ ]] around the data node, and it works beautifully. However, this doesn't work with mysql. I've tried different text, varchar, blob data types to the same effect. It seems that the browser would see the tags and just read them as html, but I guess I'm missing something. I really prefer to keep the html tags for certain purposes. I know how to place html tags around bits of data and all that, but I want the text to come preformatted. There's got to be a way! Can anyone help me?? Quote Link to comment https://forums.phpfreaks.com/topic/155966-rendering-html-from-a-mysql-table/ Share on other sites More sharing options...
jackpf Posted April 28, 2009 Share Posted April 28, 2009 You must be converting it to html special characters upon inserting it into the database. If you want to display it properly, you shouldn't do that. However, you can use htmlentitied_decode() to reverse it. Quote Link to comment https://forums.phpfreaks.com/topic/155966-rendering-html-from-a-mysql-table/#findComment-820983 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.