PHP uses RSS to subscribe to manuscripts elsewhere

Source: Internet
Author: User
Tags cdata xsl
PHP uses RSS to subscribe to articles elsewhere

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><! [Cdata[International News-Sina]]></title>
   
   <title><! [Cdata[News Center-International News]]></title>
   
    
   Http://news.sina.com.cn/world
   
    
     Http://www.sinaimg.cn/home/deco/2009/0330/logo_home_news.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
    
   
   
    

    
   
   
    
 
     <! [cdata[111 countries support a moratorium on the use of the death penalty in 41 countries against]]>
 
     http://go.rss.sina.com.cn/redirect.php?url=http://news.sina.com.cn/w/2012-12-22/120825871683. ShtmlWWW.SINA.COM.CN 
     
      http://go.rss.sina.com.cn/redirect.php?url=http://news.sina.com.cn/w/2012-12-22/ 120825871683.shtml
        【法新社联合国12月20日电】周四,在联大讨论人权问题的主旨会议上,有创纪录的111个国家投票支持暂缓使用死刑。  虽然这次投票在法律上不具备约束力,但是人权活动分子说,每两年举行一次的表决,是向那些依然保留死刑的国家发出的强烈信号,这些数量在逐步减少的国家.... 
      
     
       
      
      Sat, 04:08:09 GMT 
      国际新闻-焦点新闻 
 
      
 
 
 
 

    
     
  
 

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      
 
  

The example of RSS

    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:

Ok, that's all .... Inf!!

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