•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 397,843 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,537 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 894 | Replies: 1
![]() |
•
•
Join Date: Oct 2006
Posts: 5
Reputation:
Rep Power: 0
Solved Threads: 0
Hi, I have two websites. I have an RSS feed from one that I want to host on the other, just the headlines and links back to the second website...
Right now I'm using SimpleXML and fopen/fclose to bring in the XML documents. But for some reason it's not working... here is the code I have now:
The RSS feed right now is just:
Any ideas? Or is there a better way to do this?
Right now I'm using SimpleXML and fopen/fclose to bring in the XML documents. But for some reason it's not working... here is the code I have now:
<?php
$url = 'http://www.mywebsite.com/rss.xml';
$rss_file = fopen($url, r);
$xml = simpleXML_load_file($url);
foreach ($xml->item as $item) {
echo $item->title . '<br />';
}
fclose($rss_file);
?> The RSS feed right now is just:
<item> <title>This is a title</title> <description>This is a desctription...</description> </item>
Any ideas? Or is there a better way to do this?
Last edited by tleisher : Jul 12th, 2007 at 6:15 pm.
•
•
•
•
Hi, I have two websites. I have an RSS feed from one that I want to host on the other, just the headlines and links back to the second website...
Right now I'm using SimpleXML and fopen/fclose to bring in the XML documents. But for some reason it's not working... here is the code I have now:
<?php $url = 'http://www.mywebsite.com/rss.xml'; $rss_file = fopen($url, r); $xml = simpleXML_load_file($url); foreach ($xml->item as $item) { echo $item->title . '<br />'; } fclose($rss_file); ?>
The RSS feed right now is just:
<item> <title>This is a title</title> <description>This is a desctription...</description> </item>
Any ideas? Or is there a better way to do this?
You don't need the fopen() call.
Here's the correct code:
$url = 'http://example.com/rss.xml';
$xml = simpleXML_load_file($url);
echo '<pre>'.htmlentities(print_r($xml, 1)).'</pre>';
foreach ($xml->channel->item as $item) {
echo $item->title . '<br />';
}simpleXML_load_file() will retrieve the contents of the xml file and parse it into an Object.
This line:
echo '<pre>'.htmlentities(print_r($xml, 1)).'</pre>';
will show you the structure of the $xml returned by simpleXML_load_file($url);
Its the same as var_dump() but it's a bit more readable.
The items are in in the array: $xml->channel->item
--
It's probably easier if you use an RSS lib since it simplifies the structure of the xml object for you. If you simpleXML_load_file() on a different type of RSS or ATOM feed for instance, you'll get a different structure since the XML structure changes.
Good one to try is: magpie RSS.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
- learning php (PHP)
- PHP and XML (PHP)
- Searching XML documents with PHP (PHP)
- Help -regarding Loading Labels In Html From Xml Using Javascript Or Php (JavaScript / DHTML / AJAX)
- interact between php and flash using xml (PHP)
- Need some help with parsing an XML file (PHP)
- Dealing With XML in Visual C++ (C++)
- Php parser error when xml version is mentioned (PHP)
Other Threads in the PHP Forum
- Previous Thread: Uploading File Not Working...simple code, what's wrong?
- Next Thread: Face a problem and asking for help


Linear Mode