I'm working on some OO PHP code to generate an RSS feed from a postgreSQL database. The data is stored in the database with special characters (eg ä, etc) as well as text containing strings wrapped in single quotes and double quotes. I've looked at hmtlentities() and htmlspecialchars() .

// Remove HTML special characters from displays.
function cleanHTMLChars()
{
return htmlspecialchars($this->text) ;
}

// Format a block of text.
function formatTextBlock()
{
//
// Trim leading and trailing spaces.
$text = trim($this->text) ;
//
// Replace HTML chars.
$text = $this->cleanHTMLChars($text) ;
//
// Replace new lines with <br>
$text = ereg_replace("\n","<br>", $text);
//
// Return our text.
return $text ;
}

So far I have drawn a blank at getting these characters displayed. For those browsers that I can see the feed, where the apostrophes should be is replaced by a ? and if they encounter a special character, such as an ä, a message saying "An invalid character was found ....".

Any help would be appreciated. I'm fairly new to PHP OO and still learning as I go, so forgive me if this sounds simple to do to some coders.

Thank you

    what charset are they stored in the db as?
    what encoding are you using for the rss feed?

    if you use matching charsets\encoding you should be ok

      You may want to use [man]htmlentities/man instead of htmlspecialchars().

        4 days later

        The charset on the postgresql database is set to SQL_ASCII and I believe the XML parser for the feed recognises only UTF-8, so I need to find a way of converting the dabases charset. I did come across a php function called mb_convert_encoding() but alas this is un undefined function in current set up of PHP - have requested a new build :-)

        Have also seen iconv() as a possible, but again not getting it to work yet either.


        dagon wrote:

        what charset are they stored in the db as?
        what encoding are you using for the rss feed?

        if you use matching charsets\encoding you should be ok

          I found a function on php.net when looking under htmlentities called xmlentities down in the contributor notes which I am also trying. This does call htmlentities inside, but so far no luck in getting the accented characters displayed.


          NogDog wrote:

          You may want to use [man]htmlentities/man instead of htmlspecialchars().

            a month later

            I have already tried htmlentities() but still not displaying in the RSS feed, so took it back out.

              Write a Reply...