Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Old 10-15-2008, 03:39 PM   PM User | #1
LJackson
Senior Coder

 
Join Date: Jun 2008
Location: Cornwall
Posts: 1,612
Thanks: 231
Thanked 12 Times in 12 Posts
LJackson has a little shameless behaviour in the past
Exclamation How do i display RSS feeds in my php page?

Hi All,

I have suscribed to some rss feeds and can view in windows live mail but how do i get my website to display the rss feeds?

here is one of the feeds url

http://ax.phobos.apple.com.edgesuite...15427%26url%3D

i know very little about rss,

i will also be calling these feeds from a database, so depending on which page is loaded the relivant feed is shown.

many thanks
Luke
LJackson is offline   Reply With Quote
Old 10-15-2008, 05:29 PM   PM User | #2
angst
Senior Coder

 
angst's Avatar
 
Join Date: Apr 2004
Location: Toronto, Ontario
Posts: 1,766
Thanks: 12
Thanked 82 Times in 82 Posts
angst is on a distinguished road
have a look here: http://us2.php.net/manual/en/simplexml.examples.php
angst is offline   Reply With Quote
Old 10-15-2008, 05:34 PM   PM User | #3
LJackson
Senior Coder

 
Join Date: Jun 2008
Location: Cornwall
Posts: 1,612
Thanks: 231
Thanked 12 Times in 12 Posts
LJackson has a little shameless behaviour in the past
hi thanks for your reply, unfortunatly that link looks way to complex. plus i dont know how to get the xml file?

i dont know anything about rss, so please make everything as basic as possible

thanks
LJackson is offline   Reply With Quote
Old 10-15-2008, 07:06 PM   PM User | #4
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 5,228
Thanks: 4
Thanked 414 Times in 412 Posts
mlseim will become famous soon enoughmlseim will become famous soon enough
This is the simplest example I could come up with:

PHP Code:
<?php  
// rss page for Testing -  
$feed_url "http://ax.phobos.apple.com.edgesuite.net/WebObjects/MZStore.woa/wpa/MRSS/topsongs/sf=143444/limit=25/rss.xml?partnerId=2003&TD_PARAM=http%3A%2F%2Fclkuk.tradedoubler.com%2Fclick%3Fp%3D23708%26a%3D1515427%26url%3D";

// INITIATE CURL. 
$curl curl_init(); 

// CURL SETTINGS. 
curl_setopt($curlCURLOPT_URL,"$feed_url"); 
curl_setopt($curlCURLOPT_RETURNTRANSFER1); 
curl_setopt($curlCURLOPT_CONNECTTIMEOUT0); 

// GRAB THE XML FILE. 
$xmlTwitter curl_exec($curl); 

curl_close($curl); 

// SET UP XML OBJECT.
// Use either one of these, depending on revision of PHP.
// Comment-out the line you are not using.
//$xml = new SimpleXMLElement($xmlTwitter);
$xml simplexml_load_string($xmlTwitter); 

// How many items to display 
$count 10

// How many characters from each item 
// 0 (zero) will show them all. 
$char 200

foreach (
$xml->channel->item as $item) { 
if(
$char == 0){ 
$newstring $item->description

else{ 
$newstring substr($item->description0$char); 

if(
$count 0){ 
//in case they have non-closed italics or bold, etc ... 
echo"</i></b></u></a>\n"
echo

<div style='font-family:arial; font-size:.8em;'>  
<b>{$item->title}</b><br />
$newstring ... <a href='{$item->guid}'>read more</a> 
<br /><br /> 
</div> 
"
;  

$count--; 
}  
?>

We of course are not sure of what XML tags you are interested in.
__________________


.
mlseim is offline   Reply With Quote
Old 10-15-2008, 07:12 PM   PM User | #5
runnerjp
Regular Coder

 
Join Date: Nov 2006
Posts: 601
Thanks: 1
Thanked 2 Times in 2 Posts
runnerjp can only hope to improve
ok i quickly typed this up for you...simple enough .. ok


call your file rss.php or what ever you want

PHP Code:
<?php
header
('Content-type: text/xml'); //change file type to XML
include("the database!");  //get config
?>
<rss version="2.0">
<channel>
    <title>Feed Name</title>
    <description>Feed Descriptiondescription>
    <link>http://yoursite.com</link>
<?
$result 
mysql_query("SELECT * FROM entries ORDER BY id DESC"); //get the information
while($row mysql_fetch_assoc($result)){ //repeat the info
?>
<item>
     <title><?=$row['title']; //echo the title
?></title>
     <description><?=$row[short]; //echo the content
?></description>
     <author>SiteName submissions@yoursite.com</author>
     <link>http://yoursite.com/index.php?id=<?=$row['id']; //another link to the article
?></link>
     <guid>http://yoursite.com/#<?=$row[id];// Quick Link
?></guid>
</item>
<?
//end the while
?>
</channel>
</rss>
Be sure to change all your variables and upon checking it with W3C Feed Validator it is valid.
Now you have to edit your .htaccess file =P
Please add the code below so that instead of rss.php you could use news.xml or something else.

Code:
RewriteEngine On
RewriteRule ^(.*).xml$ rss.php
runnerjp is offline   Reply With Quote
Old 10-15-2008, 07:25 PM   PM User | #6
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 5,228
Thanks: 4
Thanked 414 Times in 412 Posts
mlseim will become famous soon enoughmlseim will become famous soon enough
RunnerJP ...

I think they are looking for an RSS "Reader", not "Feeder".
But I like your feed example and may play with that one myself ... thanks for posting.
__________________


.
mlseim is offline   Reply With Quote
Old 10-15-2008, 07:29 PM   PM User | #7
runnerjp
Regular Coder

 
Join Date: Nov 2006
Posts: 601
Thanks: 1
Thanked 2 Times in 2 Posts
runnerjp can only hope to improve
woops sorry miss understood ... thanks i do some erros in my codeing as you know by all my posts but sometimes i hit it right haha
runnerjp is offline   Reply With Quote
Old 10-15-2008, 10:14 PM   PM User | #8
LJackson
Senior Coder

 
Join Date: Jun 2008
Location: Cornwall
Posts: 1,612
Thanks: 231
Thanked 12 Times in 12 Posts
LJackson has a little shameless behaviour in the past
Quote:
Originally Posted by mlseim View Post
This is the simplest example I could come up with:

PHP Code:
<?php  
// rss page for Testing -  
$feed_url "http://ax.phobos.apple.com.edgesuite.net/WebObjects/MZStore.woa/wpa/MRSS/topsongs/sf=143444/limit=25/rss.xml?partnerId=2003&TD_PARAM=http%3A%2F%2Fclkuk.tradedoubler.com%2Fclick%3Fp%3D23708%26a%3D1515427%26url%3D";

// INITIATE CURL. 
$curl curl_init(); 

// CURL SETTINGS. 
curl_setopt($curlCURLOPT_URL,"$feed_url"); 
curl_setopt($curlCURLOPT_RETURNTRANSFER1); 
curl_setopt($curlCURLOPT_CONNECTTIMEOUT0); 

// GRAB THE XML FILE. 
$xmlTwitter curl_exec($curl); 

curl_close($curl); 

// SET UP XML OBJECT.
// Use either one of these, depending on revision of PHP.
// Comment-out the line you are not using.
//$xml = new SimpleXMLElement($xmlTwitter);
$xml simplexml_load_string($xmlTwitter); 

// How many items to display 
$count 10

// How many characters from each item 
// 0 (zero) will show them all. 
$char 200

foreach (
$xml->channel->item as $item) { 
if(
$char == 0){ 
$newstring $item->description

else{ 
$newstring substr($item->description0$char); 

if(
$count 0){ 
//in case they have non-closed italics or bold, etc ... 
echo"</i></b></u></a>\n"
echo

<div style='font-family:arial; font-size:.8em;'>  
<b>{$item->title}</b><br />
$newstring ... <a href='{$item->guid}'>read more</a> 
<br /><br /> 
</div> 
"
;  

$count--; 
}  
?>
Firstly Thanks Mate for doing this, what i dont understand is the xml file. where is it? how do i get it, is it a physical file that i should have or is it something that is pulled out of the rss feed? sorry for being dumb but i dont understand any of this rss stuff (but i will )

your above code im getting an error:
Fatal error: Call to undefined function curl_init() in C:\wamp\www\Affiliate\rss.php on line 14

Quote:
We of course are not sure of what XML tags you are interested in
Neither do i mate think i had better use them all until i get a feel for what im doing

thanks for you help so far much appreciated
Luke
LJackson is offline   Reply With Quote
Old 10-15-2008, 10:16 PM   PM User | #9
LJackson
Senior Coder

 
Join Date: Jun 2008
Location: Cornwall
Posts: 1,612
Thanks: 231
Thanked 12 Times in 12 Posts
LJackson has a little shameless behaviour in the past
thanks for your code runnerjp but apparently its not what im looking for, i wouldnt have known if mlseim hadnt said

but thanks for trying to help i appreciate it.
LJackson is offline   Reply With Quote
Old 10-16-2008, 03:22 AM   PM User | #10
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 5,228
Thanks: 4
Thanked 414 Times in 412 Posts
mlseim will become famous soon enoughmlseim will become famous soon enough
Your server (or webhost) must not have PHP CURL installed or enabled.

A web site that provides RSS feeds use their database to create an XML file.
The URL you gave us in the first post is a URL to their XML file. The XML file
is a specific set of tags that define XML.

An RSS reader opens that XML file and reads the fields (or tags) you're interested
in knowing. Once you read the tags, they can be displayed on your web page.

You might ask ... "why would a web site give out information for people to use on their own web site?" The answer is, with RSS, there are usually links back to the source.
So, it gives them links to their site, and some added traffic.

Here's an RSS feed I use to generate a little weather thing on a web page:
http://www.catpin.com/weather

Use Google to search more about RSS feeds.

About your script failing ... contact your web host about PHP CURL.
__________________


.
mlseim is offline   Reply With Quote
Old 10-16-2008, 01:35 PM   PM User | #11
LJackson
Senior Coder

 
Join Date: Jun 2008
Location: Cornwall
Posts: 1,612
Thanks: 231
Thanked 12 Times in 12 Posts
LJackson has a little shameless behaviour in the past
ok i now understand the xml bit thanks.

the curl error - might that be caused by the fact im on the local host at the moment?

cheers
Luke
LJackson is offline   Reply With Quote
Old 10-16-2008, 02:48 PM   PM User | #12
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 5,228
Thanks: 4
Thanked 414 Times in 412 Posts
mlseim will become famous soon enoughmlseim will become famous soon enough
Luke ...

That might be it ... upload to a webhost and the CURL would work.
Most hosts now have CURL enabled.

More about XML ...
http://www.xml.com/pub/a/98/10/guide0.html?page=2#AEN66
__________________


.
mlseim is offline   Reply With Quote
Old 10-16-2008, 03:03 PM   PM User | #13
LJackson
Senior Coder

 
Join Date: Jun 2008
Location: Cornwall
Posts: 1,612
Thanks: 231
Thanked 12 Times in 12 Posts
LJackson has a little shameless behaviour in the past
my host does not support Curl damn One.com

are there any other ways around it?
LJackson is offline   Reply With Quote
Old 10-16-2008, 05:01 PM   PM User | #14
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 5,228
Thanks: 4
Thanked 414 Times in 412 Posts
mlseim will become famous soon enoughmlseim will become famous soon enough
See if this works on your server ....

PHP Code:
<?php  
// rss page for Testing -  
$feed_url "http://ax.phobos.apple.com.edgesuite.net/WebObjects/MZStore.woa/wpa/MRSS/topsongs/sf=143444/limit=25/rss.xml?partnerId=2003&TD_PARAM=http%3A%2F%2Fclkuk.tradedoubler.com%2Fclick%3Fp%3D23708%26a%3D1515427%26url%3D";

$xml simplexml_load_file($feed_url);

// How many items to display 
$count 10

// How many characters from each item 
// 0 (zero) will show them all. 
$char 200

foreach (
$xml->channel->item as $item) { 
if(
$char == 0){ 
$newstring $item->description

else{ 
$newstring substr($item->description0$char); 

if(
$count 0){ 
//in case they have non-closed italics or bold, etc ... 
echo"</i></b></u></a>\n"
echo

<div style='font-family:arial; font-size:.8em;'>  
<b>{$item->title}</b><br />
$newstring ... <a href='{$item->guid}'>read more</a> 
<br /><br /> 
</div> 
"
;  

$count--; 
}


?>
__________________


.
mlseim is offline   Reply With Quote
Users who have thanked mlseim for this post:
LJackson (10-16-2008)
Old 10-16-2008, 05:13 PM   PM User | #15
LJackson
Senior Coder

 
Join Date: Jun 2008
Location: Cornwall
Posts: 1,612
Thanks: 231
Thanked 12 Times in 12 Posts
LJackson has a little shameless behaviour in the past


Yes mate it does thank you so much for this i really appreciate it.

is it possible to get the images to show up as well?
if its not too much of a pain in the arse.

cheers mate your a star!!!!!!!
LJackson is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:04 PM.

Home - Contact Us - Archives - Link to CF - Resources - Top 

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.