decoding HTML tags from a database into a php page

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
vongurdy
Forum Newbie
Posts: 2
Joined: Tue Mar 24, 2009 1:39 pm

decoding HTML tags from a database into a php page

Post 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
NOmeR1
Forum Newbie
Posts: 8
Joined: Sat Feb 14, 2009 8:32 am

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

Post 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
?>
vongurdy
Forum Newbie
Posts: 2
Joined: Tue Mar 24, 2009 1:39 pm

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

Post by vongurdy »

NOmeR1 it worked nicely, Thank you so much.
Post Reply