How to parse RSS in PHP

Source: Internet
Author: User
Tags foreach php code

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://");
$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" >
<title>our Demo rss</title>
<description>a Test rss</description>
<pubDate> $now </pubDate>
<lastBuildDate> $now </lastBuildDate>
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.

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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: and provide relevant evidence. A staff member will contact you within 5 working days.