PHP PHP:创建一个对象数组来存储原子rss数据
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP PHP:创建一个对象数组来存储原子rss数据相关的知识,希望对你有一定的参考价值。
<?php
error_reporting(E_ALL); // shows all errors, remove this on live sites
$feedURL = 'http://mydomain.com/rss/example.xml';
$getFILE = get_content($feedURL) or die("feed not loading");
$xml = simplexml_load_string($getFILE, NULL, LIBXML_NOCDATA); // Set CDATA as text nodes
$xml->registerXPathNamespace('atom', 'http://www.w3.org/2005/Atom'); // define namespace atom
class oEntry
{
public $url;
public $author;
public $date;
public $text;
function oEntry($url, $author, $date, $text) {
$this->url = $url;
$this->author = $author;
$this->date = $date;
$this->text = $text;
}
}
foreach($xml->xpath('atom:entry') as $entry) {
// array of objects
$e[] = new oEntry($xml->link['href'], $entry->author->name, $entry->published, $entry->content);
} // end foreach
?>
SAMPLE XML INPUT (you need to fill out the tags):
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0">
<link rel="alternate" type="text/html" href="" />
<id></id>
<updated></updated>
<title></title>
<entry>
<id></id>
<thr:in-reply-to ref="" type="text/html" href=""/>
<link rel="alternate" type="text/html" href="" />
<title></title>
<author>
<name></name>
<uri></uri>
</author>
<content type="html" xml:lang="en-us" xml:base="">
<![CDATA[<p>html text goes here</p>]]>
</content>
<published>February 20, 2010 2:23 AM</published>
</entry>
</feed>
以上是关于PHP PHP:创建一个对象数组来存储原子rss数据的主要内容,如果未能解决你的问题,请参考以下文章
PHP:索引大型RSS源数组
php如何序列化对象数组?
PHP 操作大对象 数组如何节省内存
当rss feed改变php时如何播放声音
PHP数组中可否存放对象?如果可以,那么在smarty的模板中应当如何获取对象的属性值?
用php将对象存储在数组中