search
Homephp教程php手册PHP利用RSS订阅别处文章

PHP利用RSS订阅别处文章

Jun 13, 2016 am 11:34 AM
phprssxmlusebased onoperatedocumentarticleyesofsubscription

 这篇文章是接上篇利用PHP操作XML文件的。RSS是基于XML的一种形式,它的具体规范如下(我们以截取的新浪RSS订阅频道的格式来看):

输入:http://rss.sina.com.cn/news/world/focus15.xml 查看页面源码就可以看到RSS的结构:





<br> <br>

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



Sat, 22 Dec 2012 05:32:05 GMT




<br> <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, 22 Dec 2012 04:08:09 GMT



虽然这次投票在法律上不具备约束力,但是人权活动分子说,每两年举行一次的表决,是向那些依然保留死刑的国家发出的强烈信号,这些数量在逐步减少的国家....]]>




具体规范信息是代表什么意思,根据标签的内容我们就可以很容易的知道,下面我们写一个rss.php来读取这个xml,从而获取这上面的文章:

 




XML


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

The example of RSS





注意这个函数:simplexml_load_file() ; 它既可以读本地的xml文件,也可以读网络上的xml。

运行结果:

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment