Hello, I hit a brick wall with the conversion of quotes in what is my first ever RSS feed, which I am generating with PHP from content that is in a MySQL database.

Basically Safari's RSS reader and Google's RSS reader (opened in FireFox) both display the quotes correctly but FireFox's own RSS reader and NewsGator online RSS reader (opened in Safari) don't display them correctly. Instead of single quotes and double quotes they show a question mark in a black diamond single. The same also happens in my iPhone's RSS reader. You can see what I am talking about here: http://www.chaindlk.com/reviews/rss.php

I have tried all of the following:

$review = str_replace('<br />','',$object->text);
$review = htmlspecialchars($review,ENT_QUOTES);
$review = str_replace(''','&39;',$review);
$review = str_replace('"','&quot;',$review);

but none of them seem to work.
Can anyone point me in the right direction?
Thanks so much

    I still have no solution but I figured out that it has something to do with character encoding.

    The first few lines of my rss.php file are the following:

    <?php
    header("Content-Type:application/xml;charset=UTF-8");
    echo '<?xml version="1.0" encoding="UTF-8"?>
    ';
    ?>
    <rss version="2.0" xmlns:reviews="http://www.chaindlk.com/reviews/">
     <channel>
    ...

    I noticed that if I leave it as it is I get this:
    built in RSS reader in Safari: NO
    Google RSS reader in Safari: YES
    NewsGator RSS reader in Safari: NO
    built in RSS reader in Firefox: NO
    Google RSS reader in Firefox: YES
    NewsGator RSS reader in Firefox: NO

    If I change the first few lines to this:

    <?php
    header("Content-Type:application/xml;charset=iso-8859-1");
    echo '<?xml version="1.0" encoding="iso-8859-1"?>
    ';
    ?>
    <rss version="2.0" xmlns:reviews="http://www.chaindlk.com/reviews/">
     <channel>
    ...

    then I get these results:
    built in RSS reader in Safari: YES
    Google RSS reader in Safari: YES
    NewsGator RSS reader in Safari: NO
    built in RSS reader in Firefox: YES
    Google RSS reader in Firefox: YES
    NewsGator RSS reader in Firefox: NO

    If I remove the character encoding specifications altogether in both the instances then I get this mixed result:
    built in RSS reader in Safari: YES
    Google RSS reader in Safari: YES
    NewsGator RSS reader in Safari: NO
    built in RSS reader in Firefox: NO
    Google RSS reader in Firefox: YES
    NewsGator RSS reader in Firefox: NO

    I also tried replacing application/xml with text/xml but nothing changed (I don't know what the difference is).

    Any ideas how to interpret this and with what character encoding to go?

      I would guess that your text was originally created in MS Word, perhaps? If so, it uses some character encodings that do not exist in UTF-8. You could use this function to filter the output. (It does not copy-and-paste well here due to all the special character codes.)

        You are a genius NogDog! Thank you!
        Yes indeed some of my contributors unfortunately still believe in Microsoft and in Word... what can I do!?!? ;-)

        This function seems to work... It DOES work in both built in readers of Safari and Firefox and I have a feeling it will also work in NewsGator and Google Reader but I was unable to confirm that it works on Google's reader and NewsGator because I can't seem to have the feed be refreshed there... I am reloading the page and clicking the refresh button but it doesn't want to refresh... I even removed the feed and re-added it and that doesn't work either. I know that it's not refreshing because I posted a new post in the meantime and the post doesn't appear at all, so I know it's not refreshing...

        On a different note, does anyone know if there is a way to tell my RSS feed not to cache or to always be expired so that the browser always restores it?

          marcnyc;10898819 wrote:

          You are a genius NogDog! Thank you!
          On a different note, does anyone know if there is a way to tell my RSS feed not to cache or to always be expired so that the browser always restores it?

          header("Cache-Control: no-cache, must-revalidate");
          header("Expires: Mon, 26 Jun 1989 07:00:00 GMT");
          

          That should do it.

          Edit: just make sure, of course, that those are output before any content gets passed to the browser, even newlines.

            Horizon88;10898842 wrote:
            header("Cache-Control: no-cache, must-revalidate");
            header("Expires: Mon, 26 Jun 1989 07:00:00 GMT");
            

            That should do it.

            Edit: just make sure, of course, that those are output before any content gets passed to the browser, even newlines.

            Thank you for that.
            Unfortunately there seems to be a little issue with that. I now see duplicate posts.
            My uneducated guess is that it is because I have the RSS publication date set us the present time of when the page is loaded:

            		<pubDate>'.date('r',strtotime($object->date)).'</pubDate>

            and so now a previously-unread post shows up again.
            You know what I mean?

            NogDog;10898847 wrote:

            You might also want to include a <ttl> value.

            I tried the TTL suggestion (a good one) but right now I am still seeing all these duplicates.. I will change the value to 5 minutes and see if that changes anything

              Try setting a

              <guid>unique random static value here</guid>

              to avoid the duplicate post issues.

              I usually use md5(post_title+post_description+post_id); to generate my GUIDs, so if either the title or the description changes, it updates the GUID accordingly and shows a changed item.

                clever
                if that's the case I should be able to just use rand(), no?

                  You could, but rand() could give you duplicates, as it is random. The XML spec says guid needs to be unique, so if you have duplicate guid values for two different items, your feed won't validate. Doing it my way gives you the benefit of having unique ids without duplicates, compliant code, and the feed will show a new event if you modify the title, description, or any other field you include in the MD5 hash, whereas just a random guid won't. You should also probably use SHA1, just for best practices, instead of MD5, as SHA1 is supposed to be less likely to have collisions.

                    No problem. Don't forget to mark this thread resolved if we've covered everything, please.

                      Write a Reply...