User325313 User325313 - 3 months ago 19
PHP Question

Can't extract rss feed item title

I'm using a php code to extract the title of an ebay affiliate (Partner Network) rss, but I'm having no success. What am I doing wrong?
By the way, is it possible to link the title too?

PHP



<?php
$xml = new DOMDocument();
@$xml->loadHTMLFile('http://rest.ebay.com/epn/v1/find/item.rss?keyword=%28jewelry%2Ccraft%2Cclothing%2Cshoes%2Cdiy%29&sortOrder=BestMatch&programid=1&campaignid=5337945426&toolid=10039&listingType1=All&lgeo=1&topRatedSeller=true&hideDuplicateItems=true&entriesPerPage=2&feedType=rss');

$products = array();

//Loop through each <td> tag in the dom and extract inner html

foreach($xml->getElementsByTagName('td') as $p) {
$children = $p->childNodes;
$phtml = '';
foreach ($children as $child)
{
$phtml.= $p->ownerDocument->saveHTML($child);
}

echo '<div id="mainproductafilioright1"><div class="product">' . $phtml . '</div></div>';
}
?>

Answer

You're on the right way. While checking the feed page I could see that the td elements are inside the <![CDATA[. but the title is outside it, that's why you can't get the title.

Try this temporary solution (This is a completely new code, not to be inserted with the older one):

$feedurl = "http://rest.ebay.com/epn/v1/find/item.rss?keyword=%28jewelry%2Ccraft%2Cclothing%2Cshoes%2Cdiy%29&sortOrder=BestMatch&programid=1&campaignid=5337945426&toolid=10039&listingType1=All&lgeo=1&topRatedSeller=true&hideDuplicateItems=true&entriesPerPage=8&feedType=rss";

$rss = simplexml_load_file($feedurl);

foreach ($rss->channel->item as $item) {

$link = $item->link;

$title = $item->title;

$description = $item->description;

}

You can output it using print:

print = $description;