Slashdot(RSS) + PHP(SimpleXML) = {My} Slashdot Rss Reader

I read slashdot.

I use PHP (with xampp on a local machine).

Figured I’d post a hello world-ish script allowing folks reading these posts to write their own RSS readers, can easily be converted for other website’s feeds as well:

So here goes (have fun) :

<body>
<div class=”feed”>

<?php
$feed = ‘http://rss.slashdot.org/Slashdot/slashdot&#8217;;
$data = new SimpleXMLElement($feed,NULL,true);

if(!$data)
{
echo(‘cant build feed object’);
}
else
{

foreach ($data->item as $item){
echo ‘<h2>’.$item->title.'</h2>’;
echo ‘<p>’.$item->description.'</p>’;
}
}
?>

</div>

</body>

For those who want to simply style it too:

<style>

.feed{
width:700px;
top:100px;
left:100px;
font-family:helvetica;
}

.feed h2{
background-color:maroon;
color:gold;
padding-bottom:0;
margin-bottom:0;
text-align:center;
}

.feed p{
background-color:gold;
color:maroon;
padding:0;
margin:0;
}

.feed img{
border:0px;
display:none;
}

</style>

stick theĀ  style tagged code in the head, and body tagged code in a file.php, assuming your simplexml is enabled, the feed’s gonna be displayed how you want it.

or you could just use firefox to see the contents of the feed and save the trouble of this attempt.

I did it because I felt more able to be in control of the presentation.

See ya in the next post.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s