Page 1 of 1

decoding HTML tags from a database into a php page

Posted: Tue Mar 24, 2009 1:55 pm
by vongurdy
Two questions:
1)
I created a database with a descripton field. Inside this field I also include some HTML tags for links and to format some text. The Database encodes the HTML files, for instance a break <br /> tag is written as <br />
My problem is that when I view the data in a browser it places the HTML tags with the text. Is there a way to read the html tags so links and text are displayed in elegant way?
2)
I Also trying to bind a date field and display it in a table. but it needs to be converted from Julian Day count to Gregorian date. Does anybody knows how to?

Thank you any feed back will be greatly appreciated. von

Re: decoding HTML tags from a database into a php page

Posted: Tue Mar 24, 2009 6:00 pm
by NOmeR1
vongurdy wrote:1)
I created a database with a descripton field. Inside this field I also include some HTML tags for links and to format some text. The Database encodes the HTML files, for instance a break <br /> tag is written as <br />
My problem is that when I view the data in a browser it places the HTML tags with the text. Is there a way to read the html tags so links and text are displayed in elegant way?
Use function htmlspecialchars_decode. If you have troubles with that, use following script

Code: Select all

<?php
    function htmlEncode($html) {
        $trans = get_html_translation_table(HTML_ENTITIES);
        $s = array_keys($trans);
        $t = array_values($trans);
        $text = str_replace($t,$s,$html);
        return $text;
    }
    echo htmlEncode("Text<br>Text"); // returns Text<br>Text
?>

Re: decoding HTML tags from a database into a php page

Posted: Tue Mar 24, 2009 11:15 pm
by vongurdy
NOmeR1 it worked nicely, Thank you so much.