phpXML Home | XML Test Sandbox | RSS Feed Example | Flash-to-PHP Example

To see the source code for this sample, scroll to the below the feed listing or click here.

Feed URL: http://news.com.com/2547-1_3-0-5.xml

Select a technology news feed:

Hoping to energize the electric car industry and make the Bay Area the electric car capital of the United States, San Jose, Calif., installs the first of hundreds of electric vehicle charging stations.
CNET Car Tech spent some time with the Mitsubishi i-Miev in San Francisco.
Get schooled by CNET editor Jasmine France. This week she gives tips on how you can use technology to do good things for fellow humans.
Las Vegas is the setting this week for two of the most popular annual security events. First comes Black Hat for the professional crowd, followed by the more antic Defcon gathering.
Updates to the Firefox cloud-based syncing tools for iPhone and for the Firefox browser correct three of users' top complaints, according to Mozilla.
But those reports, which said nearly all of the Internet giant's services were blocked Thursday, turned out to be erroneous.
Airprobe software, combined with hardware and crypto cracker tool, allows people to test the snoop factor of their GSM mobile phones--and even intercept calls of others.
The New York Giants and Jets will soon offer replays, statistics, and live feeds of other games to fans at the New Meadowlands Stadium.
Talks to hire the former U.S. senator as head of the film industry's trade group fall apart.
Ex-NSA and CIA head tells Black Hat crowd that rules for when military can attack foreign networks might exempt power grids and financial networks.
Though short on details, Microsoft's CEO said it is "job one" to make sure that Windows 7 is an attractive option for slates and tablets.
As Nvidia falters, AMD's ATI graphics unit is on the rise, spurred by "radical" shifts in a notoriously fickle market, says Mercury Research.
Microsoft's CEO takes the stage at the company's financial analyst meeting. CNET's Ina Fried is in Redmond with coverage live from the event.
The government using the Web to make its policies and processes more "open" sounds sunny, but the inability of a Supernova conference panel to go into much depth about it highlights its complexities.
The names and Facebook profile Web addresses for 171 million accounts are scraped from the site and posted on file-sharing site Pirate Bay.
Evatran introduces a "hands free" EV charging station that eliminates the need to remember to recharge at the end of the day--or dirty your hands.
An experiment by Topspin and the Pixies for a couple of U.K. concerts demonstrates that in the future many acts won't need ticket brokers or promoters.
The "essential use" exemption means that only customers can legally perform jailbreaks. And it doesn't stop companies such as Apple from various work-arounds, argues Stanford Law Fellow Larry Downes.
Planning a barbecue, dinner party, or anything else that means group resource gathering? Divvyus lets you dole out those tasks in an orderly fashion.
Want to put videos longer than 10 minutes up on YouTube? It's now a reality, with a new 15-minute limit.

Sample source code:
Please keep in mind that the code behind this actual page is a bit more complex than the code below because I wanted to be able to get a quick digest of technology feeds and wanted to make updating this page super easy. The actual code behind this page allows be to just type in a couple of properties for a new feed and the page automatically includes the new feed. The code below is a nice and simple version of what this page does. It's purpose is to help show you how quickly and easily the phpXML() class makes RSS aggregation possible.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
    <title>RSS Feed Sample</title>
</head>

<body>

<form name="theForm" method="post" style="margin:0px;padding:0px;">

<!-- this drop-down auto-submits to reload the new feed once a selection is made -->
<p>Select a technology news feed: 
<select name="feedID" onChange="submit()">
<option value="cnet"<?=$feedID == "cnet" " selected" "" )?>>CNET</option>
<option value="cnn"<?=$feedID == "cnn" " selected" "" )?>>CNN</option>
<option value="eweek"<?=$feedID == "eweek" " selected" "" )?>>eWeek</option>
<option value="reuters"<?=$feedID == "reuters" " selected" "" )?>>Reuters</option>
<option value="usatoday"<?=$feedID == "usatoday" " selected" "" )?>>USA Today</option>
<option value="bbc"<?=$feedID == "bbc" " selected" "" )?>>BBC</option>
<option value="wired"<?=$feedID == "wired" " selected" "" )?>>Wired</option>
</select></p>

</form>

<?php

include( "phpXML.class.php" );

// instantiate the new XML parser
$feed = new phpXML();

// our custom list of XML feed URLs
$feedList = array( 
    
"cnet" => "http://news.com.com/2547-1_3-0-5.xml",
    
"cnn" => "http://rss.cnn.com/rss/cnn_tech.rss",
    
"eweek" => "http://rssnewsapps.ziffdavis.com/tech.xml",
    
"reuters" => "http://today.reuters.com/rss/technologyNews/",
    
"usatoday" => "http://www.usatoday.com/repurposing/TechRss.xml",
    
"bbc" => "http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/technology/rss.xml"
    
"wired" => "http://www.wired.com/news/feeds/rss2/0,2610,3,00.xml"
);

// if first time to this page (not here by submit), set the default feed to show
if( !empty( $_POST["feedID"] ) )
    
$feedID $_POST["feedID"];
else
    
$feedID "cnet";

echo 
"<p>Feed URL: " $feedList[$feedID] . "</p>\n\n";

// load the XML from the URL for the selected feed
$feed->load$feedList[$feedID] );

// parse out the title of this feed's source and its website URL
echo "<p>Title of Source: " $feed->childNodes[0]->childNodes[0]->findChildByName"title" )->value "<br/>\n" .
    
"URL for Source: " $feed->childNodes[0]->childNodes[0]->findChildByName"link" )->value "</p>\n\n";

echo 
"<div class=\"feedTrough\">";
// find all nodes in the tree named, "item" 
$items $feed->getAllByName"item" );
$feedLines = array();
// iterate through list of "item" nodes and get title, sub-title, and URL
foreach( $items as $item ) {
    
// find this item's "title" node
    
$head $item->findChildByName"title" );
    
// this this item's "link" node
    
$url $item->findChildByName"link" );
    
// and, finally, get the node named, "description"
    
$subhead $item->findChildByName"description" );
    
// echo it all out in whatever layout you like
    
echo "<div class=\"heading\"><a href=\"" $url->value "\" title=\"" $head->value "\">" $head->value "</a></div>\n";
    echo 
"<div class=\"subhead\">" html_entity_decode$subhead->value ) . "</div>\n\n";
}
echo 
"</div>\n";

?>


</body>

</html>