PHP Parsing rss Method _php Tutorial

Source: Internet
Author: User

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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.