Hi, can anyone point me in the right direction with incorporating rss feeds into web sites?
Thanks.
Hi, can anyone point me in the right direction with incorporating rss feeds into web sites?
Thanks.
Good pointers from (SimpleXML) and (MagpieRSS). For quick tasks MagpieRSS is convenient, but for extracting attributes and namespaced elements you get the clearest control with SimpleXML. The symptom reports (assigning $item directly returning nothing) usually means the value you want is an attribute or a namespaced child, not the element text — so a cast to string or an attribute accessor is required.
Here is a compact SimpleXML pattern that shows the usual steps: load the feed, iterate items, read an attribute, read a plain element, and read a namespaced child. It also enables CDATA handling and suppresses parser output so you can inspect errors.
libxml_use_internal_errors(true);
$xml = simplexml_load_string($rssString, 'SimpleXMLElement', LIBXML_NOCDATA);
foreach ($xml->channel->item as $item) {
$guid = (string) $item->guid; // element text
$sourceUrl = isset($item->source) ? (string) $item->source['url'] : null; // attribute
$nss = $item->getNamespaces(true); // prefix => URI
$thumb = null;
if (isset($nss['imedia'])) {
$imedia = $item->children($nss['imedia']);
$thumb = isset($imedia->thumbURL) ? (string) $imedia->thumbURL : null;
}
} Troubleshooting tips: use var_dump($item) or echo $item->asXML() to inspect structure; getNamespaces(true) reveals actual namespace URIs (you must pass the URI to children()); cast SimpleXMLElement to string to get text; use attributes() or array access ($elem['attr']) for attributes. Practical cautions: cache remote feeds (avoid fetching per page load), sanitize output (e.g., htmlspecialchars) before printing, and use libxml_get_errors() when parsing fails.
Jump to Post— Dani 5,664Check out MagpieRSS. It makes it *very* simple to incorporate RSS feeds into a PHP-driven site.
You should check out SimpleXML from http://php.net/. Since it's the official PHP website, they have examples and such on different functions and usages of the class of SimpleXML. Well, it comes in class and function form, so have fun!
Check out MagpieRSS. It makes it *very* simple to incorporate RSS feeds into a PHP-driven site.
Thanks for the replies. I check out both options.
Check out MagpieRSS. It makes it *very* simple to incorporate RSS feeds into a PHP-driven site.
Hey Dani,
I use MagpieRSS, but I have a little problem.
In my xml file I have these lines:
<source url="http://www.example.com/export_rss.php" />
<guid>link</guid>
<imedia:thumbURL>link</imedia:thumbURL> and I don't know how to extract them.
$source_url = $item; doesn't return anything, and neither
$imedia= $item; or $imedia= $item;
Can you tell me where I wrong ?
Thank you!
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.