PHP using RSS to subscribe to articles elsewhere _php tutorial

Source: Internet
Author: User
Tags cdata xsl
This article is next to the use of PHP to manipulate XML files. RSS is a form of XML-based, and its specification is as follows (in the format of the intercepted Sina RSS subscription channel):

Input: Http://rss.sina.com.cn/news/world/focus15.xml View page source code can see the structure of RSS:





<title><BR/><! [Cdata[International News-Sina]]> <br/></title>

<title><BR/><! [Cdata[News Center-International news]]> <br/></title>
Http://news.sina.com.cn/world
/tech/uploadpic/2012-12/20121222153257335.gif


国际新闻-焦点新闻

Http://news.sina.com.cn/491/2008/0827/1.html
ZH-CN
WWW.SINA.COM.CN
5

Copyright 1996 - 2012 SINA Inc. All Rights Reserved

Sat, Dec 05:32:05 GMT




<BR/><! [cdata[111 countries support the moratorium on the use of the death penalty 41 countries such as China and the DPRK against]]> <br/>
Http://go.rss.sina.com.cn/redirect.php?url=http://news.sina.com.cn/w/2012-12-22/120825871683.shtml
WWW.SINA.COM.CN
Http://go.rss.sina.com.cn/redirect.php?url=http://news.sina.com.cn/w/2012-12-22/120825871683.shtml

国际新闻-焦点新闻

Sat, Dec 04:08:09 GMT


  【法新社联合国12月20日电】周四,在联大讨论人权问题的主旨会议上,有创纪录的111个国家投票支持暂缓使用死刑。 <br /><br>Although the vote is legally non-binding, human rights activists say that a vote every two years is a strong signal to those countries that still retain the death penalty, which are gradually declining in countries ...] ><br> </description> <br> </item>


Specific specification information is what it means, according to the contents of the label we can easily know, below we write a rss.php to read this XML, to obtain the above article:




Xml


$dom = simplexml_load_file ("Http://rss.sina.com.cn/news/world/focus15.xml");
Var_dump ($dom);
?>

The example of RSS



      foreach ($dom->channel->item as $item)
      {
      Print ("
    • ");
      Print ("link ' >");
      Print ($item->title);
      Print ("");
      Print ("
    • ");
      }
      ?>



Note This function: Simplexml_load_file (); It can read both the local XML file and the XML on the network.

Operation Result:

http://www.bkjia.com/PHPjc/371834.html www.bkjia.com true http://www.bkjia.com/PHPjc/371834.html techarticle This article is next to the use of PHP to manipulate XML files. RSS is based on a form of XML, and its specific specifications are as follows (we use the format of the intercepted Sina RSS subscription channel): Enter: ...

  • Related Article

    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.