[代码] php代码
01 | <?php |
02 | |
03 | require "XML/RSS.php" ; |
04 | $rss = new XML_RSS( "http://php.net/news.rss" ); |
05 | $rss ->parse(); |
06 | |
07 | foreach ( $rss ->getItems() as $item ) { |
08 | print_r( $item ); |
09 | } |
10 | ?> |
[代码] RSS.php
01 | <?php |
02 | |
03 | $database = "nameofthedatabase" ; |
04 | $dbconnect = mysql_pconnect(localhost, dbuser, dbpassword); |
05 | mysql_select_db( $database , $dbconnect ); |
06 | $query = "select link, headline, description from `headlines` limit 15" ; |
07 | $result = mysql_query( $query , $dbconnect ); |
08 | |
09 | while ( $line = mysql_fetch_assoc( $result )) |
10 | { |
11 | $return [] = $line ; |
12 | } |
13 | |
14 | $now = date ( "D, d M Y H:i:s T" ); |
15 | |
16 | $output = "<?xml version=\"1.0\"?> |
17 | <rss version=\"2.0\"> |
18 | <channel> |
19 | <title>Our Demo RSS</title> |
20 | <link>http: //www.tracypeterson.com/RSS/RSS.php</link> |
21 | <description>A Test RSS</description> |
22 | <language>en-us</language> |
23 | <pubDate> $now </pubDate> |
24 | <lastBuildDate> $now </lastBuildDate> |
25 | <docs>http: //someurl.com</docs> |
26 | <managingEditor>you@youremail.com</managingEditor> |
27 | <webMaster>you@youremail.com</webMaster> |
28 | "; |
29 | |
30 | foreach ( $return as $line ) |
31 | { |
32 | $output .= "<item><title>" .htmlentities( $line [ 'headline' ])."</title> |
33 | <link> ".htmlentities($line['link'])." </link> |
34 | |
35 | <description> ".htmlentities(strip_tags($line['description']))." </description> |
36 | </item>"; |
37 | } |
38 | $output .= "</channel></rss>" ; |
39 | header( "Content-Type: application/rss+xml" ); |
40 | echo $output ; |
41 | ?> |