Im new to RSS feed parsing and having a little trouble. How would I use simplepie to capture the following resource?
<enc:enclosure resource="http://images.craigslist.org/00202_lQ0CCpDIPk0_300x300.jpg" type="image/jpeg"/>
Im new to RSS feed parsing and having a little trouble. How would I use simplepie to capture the following resource?
<enc:enclosure resource="http://images.craigslist.org/00202_lQ0CCpDIPk0_300x300.jpg" type="image/jpeg"/>
You would use the get_enclosures() function.
$feed = new SimplePie();
$feed->set_feed_url('http://simplepie.org/blog/feed/');
$feed->init();
$feed->handle_content_type();
foreach ($feed->get_items() as $item)
{
foreach ($item->get_enclosures() as $enclosure)
{
echo $enclosure->embed();
}
}
Previous responder doesn't realize how SimplePie works. You don't use the get_enclosures() because the XML is not formatted as <enclosure>
...
Instead you do it like this:
require( 'autoloader.php' );
$feed = new SimplePie();
$feed->set_feed_url('https://denver.craigslist.org/search/msa?format=rss&query=left%20handed%20%7C%20lefthanded%20%7C%20lefty');
$feed->init();
$feed->handle_content_type();
foreach ($feed->get_items() as $item) {
$encs = $item->get_item_tags( 'http://purl.oclc.org/net/rss_2.0/enc#', 'enclosure' );
if ( !isset( $encs ) )
continue;
foreach ( $encs as $enclosure){
if ( !isset( $enclosure['attribs'] ) )
continue;
foreach ( $enclosure['attribs'] as $attr ) {
echo "\n" . $attr['resource'];
}
}
}