views:

15

answers:

1

I am using SimplePie to parse and display an xml feed on my site. I have two separate rss feeds and I running each one through SimplePie then displaying them in the side bar.

The problem I am having is that each feed contains smart quotes and they are displayed as odd characters in the browser. SimplePie has the encoding set as UTF-8, but the characters still show up.

I put in a small function to remove the quotes (below) but they still show up.

function killsmartquotes($content)
{
  $content = str_replace("”", "”", $content);
  $content = str_replace("“", "“", $content);
  $content = str_replace("‘", "‘", $content);
  $content = str_replace("’", "’", $content);
  $content = str_replace("—", "—", $content);

  return $content;
}


<?php foreach ($feeds[0]->get_items(0, 1) as $item): ?>
    <h5><a href="<?php echo $item->get_permalink(); ?>"><?php echo $item->get_title(); ?></a></h5> 
    <p class="feed_description"><?php echo killsmartquotes($item->get_description()); ?></p>
    <br />
    <span><?php echo $item->get_date('j F Y'); ?> | <a href="#"><?php echo $site_names[0]; ?></a>
    </span>
<?php endforeach; ?>
</li>
+1  A: 

Instead use htmlentities and do it like this:

 <?php echo htmlentities ($item->get_description(), ENT_COMPAT, "UTF-8"); ?>
shamittomar
That worked perfectly. Thanks shamittomar.
Victor Duwon
You're welcome. Please also accept the answer.
shamittomar