by DaD on Mon Jul 28, 2008 9:03 pm
Questa classe è compatibile solo con php5 è superiori ... (aggiungerei anche pd -.-)
- Code: Select all
<?php
class readrss {
public $dom;
public $items = array();
public function __construct($url, $itemTagName){
$dom = new DOMDocument();
$feed = file_get_contents($url);
$readResult = @$dom->loadXML($feed);
if(!$readResult)
throw new Exception("Error XML!");
$this->dom = $dom;
$xpath = new DOMXPath($dom);
$xpathQuery = $xpath->query("//$itemTagName");
$count = 0;
foreach($xpathQuery as $item){
$this->items[$count] = new readitem($item);
$count++;
}
}
}
class readitem {
public $itemTags = array();
public function __construct($itemNode){
foreach($itemNode->childNodes as $node)
$this->itemTags[$node->tagName] = $node->nodeValue;
}
public function __get($node){
return $this->itemTags[$node];
}
public function __set($node, $value){
$this->itemTags[$node] = $value;
}
}
?>