logo-dw

Go Back   Dreamweaver Club Forums > Hand Coders Forum > PHP
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 05-31-2013, 10:41 PM   #1
tux
tux's Avatar
 
Join Date: Feb 2007
Location: Isle of Wight, that little island right at the bottom of the UK
Posts: 657
Default Php & rss

Hello all,

Its been ages, how the hell is everybody. Been out of the coding game for a couple of years so am well rusty.

I have taken on a rebuild website for my local camera club. Mostly okay with all of it. I suppose its like riding a bike. You never really forget!

One thing I am well behind on is RSS.

Can anyone point me in the right direction in setting up an RSS feed. I want to include feeds from a few photography websites. I have found a few sites that do the donkey work for you which is fine but I would really like to know how to do it myself.

Can anyone point me in the right direction please on how to set it up XML etc. using PHP.

Thanks, Paul
tux is offline   Reply With Quote
Old 06-01-2013, 02:32 AM   #2
edbr
edbr's Avatar
 
Join Date: Aug 2005
Location: Bali
Posts: 11,175
Default

hi paul. if you want to use php then basically you musy write the headers for xml commonly you use feeds from a database . If you want to include feeds from other sites to your page then jquery has some feed readers but there are some php scripts around but ive never had cause to use them

feed from a database mysql
PHP Code:
echo '<?xml version="1.0" encoding="UTF-8" ?>';
echo '<rss version="2.0">';   
echo '<channel>'; 
echo '<title>Concord Services Bali RSS Feed</title>';    
echo '<link>http://www.concordservices-bali.com</link>';    
echo '<description>This RSS feed of the latest jobs posted .</description>';

require_once('../Connections/test.php');
mysql_select_db($database_test, $test);
$query_Recordset1 ="SELECT field1,field2,field3,field4,UNIX_TIMESTAMP(datenow) AS datenow
FROM table  ORDER by field1 DESC LIMIT 0,15";
then echo the results


PHP Code:
while($row_Recordset1 mysql_fetch_assoc($Recordset1)){
    echo 
'<item>'// Begin a news article
    
echo '<title>' ."Feed title".$row_Recordset1['field1'].'</title>'
    echo 
'<link>'."http://www.domain_name.com/page.php?recordID=".$row_Recordset1['field1'].'</link>';
    echo 
'<description>'.htmlentities(strip_tags($row_Recordset1['field1'])) .  "in "  .strip_tags($row_Recordset1[field1'])."Salary ".htmlentities( strip_tags($row_Recordset1['field1'])).    '</description>';
    
    echo '
<datenow>'.date('Dd M Y H:i:s',$row_Recordset1['datenow']).'</datenow>'; 
    echo '
</item>'; 

 
echo '
</channel>';
echo '
</rss>'; 
__________________
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas
edbr is offline   Reply With Quote
Old 06-01-2013, 03:16 PM   #3
tux
tux's Avatar
 
Join Date: Feb 2007
Location: Isle of Wight, that little island right at the bottom of the UK
Posts: 657
Default

Thanks Edbr,

I have done a bit of research and have come up with this for anyone who may find it useful.

PHP Code:
<?php
    $rss 
= new DOMDocument();
    
$rss->load('http://your_rss_feed_URL_here/');
    
$feed = array();
    foreach (
$rss->getElementsByTagName('item') as $node) {
        
$item = array ( 
            
'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
            
'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
            
'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
            
'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue,
            );
        
array_push($feed$item);
    }
    
$limit 5;
    for(
$x=0;$x<$limit;$x++) {
        
$title str_replace(' & '' &amp; '$feed[$x]['title']);
        
$link $feed[$x]['link'];
        
$description $feed[$x]['desc'];
        
$date date('l F d, Y'strtotime($feed[$x]['date']));
        echo 
'<p><strong><a href="'.$link.'" title="'.$title.'">'.$title.'</a></strong><br />';
        echo 
'<small><em>Posted on '.$date.'</em></small></p>';
        echo 
'<p>'.$description.'</p>';
    }
?>
Just put your rss feed link into the code. You will have to style it yourself of course. You can also limit the amount of feeds...

PHP Code:
$limit 5//change to suit your needs// 
I have actually put this into a function to keep it cleaner and added..

PHP Code:
substr($description0100
... to restrict the ammount of characters in the description.

Hope it helps someone.

Regards, Paul
tux is offline   Reply With Quote
Reply


Thread Tools
Display Modes

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. The time now is 06:46 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Copyright 2006 DreamweaverClub.com