How to parse RSS in PHP
This article mainly introduces the PHP parsing RSS methods, examples of PHP parsing the principle of RSS and XML file operation skills, the need for friends can refer to the following
This article explains how PHP parses RSS. Share to everyone for your reference. Specific as follows:
1. The PHP code is as follows:
The code is as follows:
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:
$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 = "
Our Demo RSS
http://www.tracypeterson.com/RSS/RSS.php
A Test RSS
En-US
$now
$now
Http://someurl.com
You@youremail.com
You@youremail.com
";
foreach ($return as $line)
{
$output. = " ". Htmlentities ($line [' headline '])."
". Htmlentities ($line [' link '])."
". Htmlentities (Strip_tags ($line [' description '])."
";
}
$output. = " ";
Header ("Content-type:application/rss+xml");
Echo $output;
?>
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/963984.html www.bkjia.com true http://www.bkjia.com/PHPjc/963984.html techarticle PHP parsing methods of RSS This article mainly introduces the PHP parsing RSS method, the example analysis of PHP parsing the principle of RSS and XML file operation skills, the need for a friend can refer to the examples of this article to tell ...