Requirements: SimplePie 1.0 Beta 2
The only currently documented way is to use the enable_xmldump() configuration option. There is another way (as of Beta 2) to quickly snap your SimplePie-enabled pages into XMLdump mode. If the page’s URL already has a querystring appended to it (page.php?keyword=value&keyword2=value2), you’d append &xmldump=true to the end of the URL. If it’s a normal page with no querystring, append ?xmldump=true to snap it into XMLdump mode.
This only works under two conditions:
How do the SimplePie plugins work with this? Let’s see. Testing version 1.2 of the plugins:
We’ll be looking into working this out in an upcoming version of our plugins.
So there you go. XMLdump has been a very handy debugging tool for us, and hopefully it can help you too.
Requirements: SimplePie 1.0 Beta 1
Early in the days of SimplePie development, I built-in functionality that I called “XMLdump” that would dump the post-processed, pre-cached XML to the screen as XML. When a feed is read, there is a certain amount of pre-cleaning we do to make sure that what we’re parsing more closely resembled valid RSS (or Atom). After this pre-cleaning is done, you can invoke XMLdump to see the XML that SimplePie will actually be parsing, just before it’s parsed.
The only currently documented way is to use the enable_xmldump() configuration option. There is another way (as of Beta 2) to quickly snap your SimplePie-enabled pages into XMLdump mode. If the page’s URL already has a querystring appended to it (page.php?keyword=value&keyword2=value2), you’d append &xmldump=true to the end of the URL. If it’s a normal page with no querystring, append ?xmldump=true to snap it into XMLdump mode.
This only works under two conditions:
How do the SimplePie plugins work with this? Let’s see. Testing version 1.2 of the plugins:
We’ll be looking into working this out in an upcoming version of our plugins.
So there you go. XMLdump has been a very handy debugging tool for us, and hopefully it can help you too.
Requirements: SimplePie 1.0 Beta 2
In my quest for making a feed parser that is intelligent, simple, and graceful, one thing that has always bugged me about online feed readers is that some people disable the ability to hotlink images.
Now, I understand why they do this, because I do it too. You don’t want a bunch of your bandwidth sucked up by people who are stealing your images for their own nefarious purposes (mwah-hah-hah!). Rather, you’d prefer to keep the images for your readers who are reading your content. Well, that’s exactly what a feed parser is for, right?
Desktop aggregators like Feed Demon and NetNewsWire are always able to just load up the images in context with the post that they’re reading, and it all makes sense. The only reason why online feed readers have a problem is because the browsers that run them respect the hotlinking rules—even if the reasons don’t make sense for the context (like trying to apply laws about CD’s to MP3’s—although they’re related, they’re different, and the rules need to be modified for the new medium).
So, we’ve decided to solve the problem in our latest release. We’ve added functionality that allows you to bypass hotlink protection for feeds that you’re trying to read online. But that isn’t what’s important. What’s important is that it’s been built in as a configuration option that is enabled by default. You don’t need to do anything to get this to work (and actually, if you’re using the JavaScript from the old version of the article, it may mess this up so be sure to remove it).
However, if you want to make sure it’s working, or otherwise force it to be on, take a look at the following code:
<?php
// Start counting time for loading...
$starttime = explode(' ', microtime());
$starttime = $starttime[1] + $starttime[0];
include('simplepie.inc');
// Parse it
$feed = new SimplePie();
if (!empty($_GET['feed'])) {
$feed->feed_url($_GET[’feed’]);
$feed->bypass_image_hotlink();
$feed->init();
}
$feed->handle_content_type();
?><!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml” xml:lang=”en-US” lang=”en-US”>
<head>
<title>SimplePie: Demo
Have fun! This code has been implemented in the demo that comes with the SimplePie Beta 2 download.
Requirements: SimplePie 1.0 Beta 2 (or newer)
Have you ever had problems displaying feeds properly on your pages? I ran into an issue a few times when I was trying to display an iTunes Music Store feed, and Beyoncé kept coming out as Beyonc[enter-garbled-text-here]. I soon realized that the problem occurred because my pages were being served as ISO-8859-1, and the iTMS feed was being sent as UTF-8.
The solution is really quite simple.
All you have to do is make sure that the page is being served and handled in the same character set that the feed is. Fortunately, SimplePie has a built-in function that handles this for you: handle_content_type().
Ideally, when you’re loading a page with SimplePie in it, you’ll do that part at the very beginning of the page. Doing so will help you serve the page correctly.
<?php
// Start counting time for loading...
$starttime = explode(' ', microtime());
$starttime = $starttime[1] + $starttime[0];
include('../simplepie.inc');
// Parse it
$feed = new SimplePie();
if (!empty($_GET['feed'])) {
$feed->feed_url($_GET[’feed’]);
$feed->init();
}
// This is the part to pay attention to
$feed->handle_content_type();
?><!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml” xml:lang=”en-US” lang=”en-US”>
<head>
We specifically want to focus in on this chunk:
$feed->handle_content_type();
What this does is:
text/html.You can also set the <meta> tag if you’d like, although the HTTP specification says that the information that gets sent by the server will override any <meta> tags that try to do the same thing.
<meta http-equiv="Content-Type" content="text/html;charset=<?php echo $feed->get_encoding(); ?>” />
If you’re loading a feed into a page dynamically (like in our Delicious AJAX demo), your best bet is to serve the page as UTF-8, since all languages are translated into UTF-8 inside SimplePie anyways.