This article mainly introduces the method of PHP parsing rss, example analysis of the PHP parsing RSS principle and XML file operation skills, need friends can refer to the
-->
This article describes the method of PHP parsing RSS. Share to everyone for your reference. Specifically as follows:
1. PHP code is as follows:
The code is as follows: <?php
Require "xml/rss.php";
$rss = new Xml_rss ("Http://php.net/news.rss");
$rss->parse ();
foreach ($rss->getitems () as $item) {
Print_r ($item);
}
?>
2. The rss.php code is as follows:
The code is as follows: <?php
$database = "Nameofthedatabase";
$dbconnect = Mysql_pconnect (localhost, dbuser, dbpassword);
mysql_select_db ($database, $dbconnect);
$query = "Select link, headline, description from ' headlines ' limit 15";
$result = mysql_query ($query, $dbconnect);
while ($line = Mysql_fetch_assoc ($result))
{
$return [] = $line;
}
$now = Date ("D, D M Y h:i:s T");
$output = "<?xml version=" 1.0 "?>
<rss version= "2.0" >
<channel>
<title>our Demo rss</title>
<link>http://www.tracypeterson.com/RSS/RSS.php</link>
<description>a Test rss</description>
<language>en-us</language>
<pubDate> $now </pubDate>
<lastBuildDate> $now </lastBuildDate>
<docs>http://someurl.com</docs>
<managingEditor>you@youremail.com</managingEditor>
<webMaster>you@youremail.com</webMaster>
";
foreach ($return as $line)
{
$output. = "<item><title>". Htmlentities ($line [' headline ']). " </title>
<link> ". Htmlentities ($line [' link '])." </link>
<description> ". Htmlentities (Strip_tags ($line [' description '])." </description>
</item> ";
}
$output. = "</channel></rss>";
Header ("Content-type:application/rss+xml");
Echo $output;
?>
I hope this article will help you with your PHP program design.